/**
  * {@inheritdoc}
  */
 public function generateMenuUrl(AdminInterface $admin, $name, array $parameters = array(), $absolute = false)
 {
     // if the admin is a child we automatically append the parent's id
     if ($admin->isChild() && $admin->hasRequest() && $admin->getRequest()->attributes->has($admin->getParent()->getIdParameter())) {
         // twig template does not accept variable hash key ... so cannot use admin.idparameter ...
         // switch value
         if (isset($parameters['id'])) {
             $parameters[$admin->getIdParameter()] = $parameters['id'];
             unset($parameters['id']);
         }
         $parameters[$admin->getParent()->getIdParameter()] = $admin->getRequest()->attributes->get($admin->getParent()->getIdParameter());
     }
     // if the admin is linked to a parent FieldDescription (ie, embedded widget)
     if ($admin->hasParentFieldDescription()) {
         // merge link parameter if any provided by the parent field
         $parameters = array_merge($parameters, $admin->getParentFieldDescription()->getOption('link_parameters', array()));
         $parameters['uniqid'] = $admin->getUniqid();
         $parameters['code'] = $admin->getCode();
         $parameters['pcode'] = $admin->getParentFieldDescription()->getAdmin()->getCode();
         $parameters['puniqid'] = $admin->getParentFieldDescription()->getAdmin()->getUniqid();
     }
     if ($name == 'update' || substr($name, -7) == '|update') {
         $parameters['uniqid'] = $admin->getUniqid();
         $parameters['code'] = $admin->getCode();
     }
     // allows to define persistent parameters
     if ($admin->hasRequest()) {
         $parameters = array_merge($admin->getPersistentParameters(), $parameters);
     }
     $code = $this->getCode($admin, $name);
     if (!array_key_exists($code, $this->caches)) {
         throw new \RuntimeException(sprintf('unable to find the route `%s`', $code));
     }
     return array('route' => $this->caches[$code], 'routeParameters' => $parameters, 'routeAbsolute' => $absolute);
 }
 /**
  * @param \Sonata\AdminBundle\Admin\AdminInterface  $admin
  * @param \Sonata\AdminBundle\Route\RouteCollection $collection
  */
 public function build(AdminInterface $admin, RouteCollection $collection)
 {
     $collection->add('list');
     $collection->add('create');
     $collection->add('batch');
     $collection->add('edit');
     $collection->add('delete');
     $collection->add('show');
     $collection->add('export');
     if ($this->manager->hasReader($admin->getClass())) {
         $collection->add('history', '/audit-history');
         $collection->add('history_view_revision', '/audit-history-view');
     }
     if ($admin->isAclEnabled()) {
         $collection->add('acl', $admin->getRouterIdParameter() . '/acl');
     }
     // an admin can have only one level of nested child
     if ($admin->getParent()) {
         return;
     }
     // add children urls
     foreach ($admin->getChildren() as $children) {
         $collection->addCollection($children->getRoutes());
     }
 }
 /**
  * @throws \RuntimeException
  * @param \Sonata\AdminBundle\Admin\AdminInterface $admin
  * @param $name
  * @param array $parameter
  * @param bool $absolute
  * @return string
  */
 public function generateUrl(AdminInterface $admin, $name, array $parameters = array(), $absolute = false)
 {
     if (!$admin->isChild()) {
         if (strpos($name, '.')) {
             $name = $admin->getCode() . '|' . $name;
         } else {
             $name = $admin->getCode() . '.' . $name;
         }
     } else {
         if ($admin->isChild()) {
             $name = $admin->getBaseCodeRoute() . '.' . $name;
             // twig template does not accept variable hash key ... so cannot use admin.idparameter ...
             // switch value
             if (isset($parameters['id'])) {
                 $parameters[$admin->getIdParameter()] = $parameters['id'];
                 unset($parameters['id']);
             }
             $parameters[$admin->getParent()->getIdParameter()] = $admin->getRequest()->get($admin->getParent()->getIdParameter());
         }
     }
     // if the admin is linked to a parent FieldDescription (ie, embedded widget)
     if ($admin->hasParentFieldDescription()) {
         // merge link parameter if any provided by the parent field
         $parameters = array_merge($parameters, $admin->getParentFieldDescription()->getOption('link_parameters', array()));
         $parameters['uniqid'] = $admin->getUniqid();
         $parameters['code'] = $admin->getCode();
         $parameters['pcode'] = $admin->getParentFieldDescription()->getAdmin()->getCode();
         $parameters['puniqid'] = $admin->getParentFieldDescription()->getAdmin()->getUniqid();
     }
     if ($name == 'update' || substr($name, -7) == '|update') {
         $parameters['uniqid'] = $admin->getUniqid();
         $parameters['code'] = $admin->getCode();
     }
     // allows to define persistent parameters
     if ($admin->hasRequest()) {
         $parameters = array_merge($admin->getPersistentParameters(), $parameters);
     }
     $route = $admin->getRoute($name);
     if (!$route) {
         throw new \RuntimeException(sprintf('unable to find the route `%s`', $name));
     }
     return $this->router->generate($route->getDefault('_sonata_name'), $parameters, $absolute);
 }
 /**
  * {@inheritdoc}
  */
 public function getBreadcrumbs(AdminInterface $admin, $action)
 {
     $breadcrumbs = array();
     if ($admin->isChild()) {
         return $this->getBreadcrumbs($admin->getParent(), $action);
     }
     $menu = $this->buildBreadcrumbs($admin, $action);
     do {
         $breadcrumbs[] = $menu;
     } while ($menu = $menu->getParent());
     $breadcrumbs = array_reverse($breadcrumbs);
     array_shift($breadcrumbs);
     return $breadcrumbs;
 }
 /**
  * List action.
  *
  * @param Request $request
  *
  * @return Response
  *
  * @throws AccessDeniedException If access is not granted
  */
 public function listAction(Request $request = null)
 {
     $request = $this->resolveRequest($request);
     $this->admin->checkAccess('list', $this->admin->getParent() ? $this->admin->getParent()->getSubject() : null);
     $preResponse = $this->preList($request);
     if ($preResponse !== null) {
         return $preResponse;
     }
     if ($listMode = $request->get('_list_mode')) {
         $this->admin->setListMode($listMode);
     }
     $datagrid = $this->admin->getDatagrid();
     $formView = $datagrid->getForm()->createView();
     // set the theme for the current Admin Form
     $this->get('twig')->getExtension('form')->renderer->setTheme($formView, $this->admin->getFilterTheme());
     return $this->render($this->admin->getTemplate('list'), array('action' => 'list', 'form' => $formView, 'datagrid' => $datagrid, 'csrf_token' => $this->getCsrfToken('sonata.batch')), null, $request);
 }
 /**
  * @param AdminInterface $admin
  */
 private function loadCache(AdminInterface $admin)
 {
     if ($admin->isChild()) {
         $this->loadCache($admin->getParent());
     } else {
         if (in_array($admin->getCode(), $this->loaded)) {
             return;
         }
         $this->caches = array_merge($this->cache->load($admin), $this->caches);
         $this->loaded[] = $admin->getCode();
     }
 }