sonata-project / SonataAdminBundle

The missing Symfony Admin Generator
https://docs.sonata-project.org/projects/SonataAdminBundle
MIT License
2.11k stars 1.26k forks source link

Wrong links in show action #4093

Closed core23 closed 4 years ago

core23 commented 8 years ago

Environment

Question Answer
Bundle version 3.4
Symfony version 2.8
php version 5.5

Subject

When you have two admins with a parent child relation and a show and edit action, you got different links in the tab menu.

Steps to reproduce

class InvoiceAdmin extends AbstractAdmin {
    // ...

    /**
     * {@inheritdoc}
     */
    protected function configureTabMenu(MenuItemInterface $menu, $action, AdminInterface $childAdmin = null)
    {
        if (!$childAdmin && !in_array($action, array('edit'))) {
            return;
        }

        $admin = $this->isChild() ? $this->getParent() : $this;

        $id = $admin->getRequest()->get('id');

        $menu->addChild($this->trans('sidemenu.link_list_sendings'), array(
            'uri' => $admin->generateUrl('core23.invoice.admin.sending.list', array(
                'id' => $id,
            )),
        ));
    }
}
class SendingAdmin extends AbstractAdmin {
    protected $parentAssociationMapping = 'invoice';

    // ...
}

admin.xml

        <service id="core23.invoice.admin.invoice" class="Core23\InvoiceBundle\Admin\InvoiceAdmin">
            <tag name="sonata.admin" manager_type="orm" group="core23_invoice" label="invoice" label_catalogue="%core23.invoice.admin.translation_domain%"
                 label_translator_strategy="sonata.admin.label.strategy.underscore" />
            <argument />
            <argument>%core23.invoice.manager.invoice.entity%</argument>
            <argument>%core23.invoice.admin.invoice.controller%</argument>

            <call method="addChild">
                <argument type="service" id="core23.invoice.admin.sending" />
            </call>
        </service>

        <service id="core23.invoice.admin.sending" class="Core23\InvoiceBundle\Admin\SendingAdmin">
            <tag name="sonata.admin" manager_type="orm" group="core23_invoice" label="sending" label_catalogue="%core23.invoice.admin.translation_domain%"
                 label_translator_strategy="sonata.admin.label.strategy.underscore" show_in_dashboard="false" />
            <argument />
            <argument>%core23.invoice.manager.sending.entity%</argument>
            <argument>%core23.invoice.admin.sending.controller%</argument>
        </service>

Expected results

viewing an edit action: /admin/core23/invoice/invoice/10/sending/list viewing a show action: /admin/core23/invoice/invoice/10/sending/list

Actual results

viewing an edit action: /admin/core23/invoice/invoice/10/sending/list viewing a show action: /admin/core23/invoice/sending/list?id=10

It looks like the show action is ignoring the parent prefix.

skurovec commented 7 years ago

Problem is still present in the latest version (3.24.0) except links are wrong in edit action and correct in the show action.

I think, that problem is in DefaultRouteGenerator.php in method getCode where section someone provide the fullname should be before section someone provide the fullname, because I have embedded admin and child admin.

It should be like this PR https://github.com/sonata-project/SonataAdminBundle/pull/3082 for issue https://github.com/sonata-project/SonataAdminBundle/issues/2505

I will try to create PR, but this should help in the meatime to other people with this problem.

merguezzz commented 6 years ago

This can be fixed by specifying child route explicitly

XXXAdmin.php

class XxxxAdmin extends AbstractAdmin {
    // ...
    protected function configureSideMenu(ItemInterface $menu, $action, AdminInterface $childAdmin = null)
    {
    // ...

        if ($this->isGranted('EDIT')) {
            $menu->addChild('CHILDS', [
                'uri' => $admin->generateUrl('app.admin.PARENT|app.admin.CHILD.list', ['id' => $id])
            ]);
        }
stale[bot] commented 4 years ago

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.