Sonataadminbundle: Wrong links in show action

Created on 22 Aug 2016  路  3Comments  路  Source: sonata-project/SonataAdminBundle

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.

Easy Pick bug

Most helpful comment

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])
            ]);
        }


All 3 comments

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.

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])
            ]);
        }


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.

Was this page helpful?
0 / 5 - 0 ratings