Closed webdevilopers closed 5 years ago
So far this is a possible workaround:
$container = $this->getConfigurationPool()->getContainer();
$menu->addChild('EGZ Report', array(
'uri' => $container->get('router')->generate('qis_contract_bundle_egz', array('contractId' => $id, 'pdf' => 1))));
This could maybe done with an Injection too:
The problem with this workaround is that the generated URL is "incorrect" when looking a the show
action of the parent where the nested Child
(ren) are listed. Here is a different admin class example:
class CompanyAdmin extends Admin
{
public $baseRouteName = 'qis_company';
public $baseRoutePattern = '/company';
protected function configureTabMenu(MenuItemInterface $menu, $action, AdminInterface $childAdmin = null)
{
if (!$childAdmin && !in_array($action, array('show'))) { return; }
$admin = $this->isChild() ? $this->getParent() : $this;
$id = $admin->getRequest()->get('id');
// unable to find the route `sonata.admin.company.qis_company_branch_list`
// @see https://github.com/sonata-project/SonataAdminBundle/issues/2853
// $menu->addChild($this->trans('Branch List'), array('uri' => $admin->generateUrl('qis_company_branch_list', array('id' => $id))));
$container = $this->getConfigurationPool()->getContainer();
$menu->addChild($this->trans('Branch List'), array('uri' => $container->get('router')->generate('qis_company_branch_list', array('id' => $id))));
}
protected function configureShowFields(ShowMapper $showMapper)
{
$showMapper
->with('Company', array('class' => 'col-md-4'))
->add('phone')
->add('fax')
->add('street')
->add('city')
->add('country')
->end()
->with('Branches', array('class' => 'col-md-4'))
->add('branches', null, array('route' => array('name' => 'show')))
->end()
;
}
}
Expected URL: http://localhost:8000/qis/company/1/branch/2/show (Generated correctly when coming from http://localhost:8000/qis/company/1/branch/list)
Same problem when coming from a template:
<a href="{{ admin.generateUrl('admin_appbundle_contract_timekeepingentry_list', { 'id': object.id }) }}"></a>
results in:
An exception has been thrown during the rendering of a template ("unable to find the route sonata.admin.contract.admin_appbundle_contract_timekeepingentry_list
")
This issue was resolved after command rm -rf app/cache/*
.
app/console cache:clear
doesn't help me.
Also, @webdevilopers you should call addChild in service. Like
<service id="acme.admin.test"
class="Acme\AcmeBundle\Admin\TestAdmin">
<tag name="sonata.admin"
manager_type="orm"
group="test"
label="Test"/>
<argument />
<argument>Acme\AcmeBundle\Entity\Test</argument>
<argument />
<call method="addChild">
<argument type="service" id="survey.admin.another"/>
</call>
</service>
I think we are talking about different things, @aivus .
The addChild
method is called on the menu
not the admin class since I stated:
I try to add an uri that is not related to an admin
.
It is a general problem with the added prefix to the url.
:+1:
It look likes we even can't just link to another admin if they are not parent/child:
An exception has been thrown during the rendering of a template ("unable to find the route
sonata.admin.gallery|sonata.admin.user.list
") in SonataAdminBundle:CRUD:base_edit.html.twig at line 34.
$menu->addChild(
"Users",
$admin->generateMenuUrl('sonata.admin.user.list', array('filter' => ['gallery' => ['value' => $id]]))
);
Too bad this is not allowed :]
If the routes of Admin Class ( $baseRouteName and $baseRoutePattern ) are overriden, ( the one of the child or the one of the parent ) the chlid routes are not beeing generated http://stackoverflow.com/questions/28636229/child-admin-route-is-not-being-generated-sonata-admin-bundle
This issue is very old. Can you please check this against the latest stable / master version?
Feel free to reopen, if the error still exists.
A PR would be welcome to if you reopen this issue.
Sorry, but I'm no longer working on this project.
Normally I add a child to the tab menu by generating the admin related Url like this:
But when I try to add an uri that is not related to an admin but for instance a standalone Controller:
like this:
I get an exception: _An exception has been thrown during the rendering of a template ("unable to find the route
sonata.admin.contract.qis_contract_bundle_egz
") in SonataAdminBundle:CRUD:base_edit.html.twig at line 34. _The Url generator assumes there is an admin class and prefixes the
uri
withsonata.admin.contract.
.How can I change this behaviour?
Possibly related issue: