Ejemplo n.º 1
0
 /**
  * Generates the breadcrumbs array
  *
  * @param string                       $action
  * @param \Knp\Menu\ItemInterface|null $menu
  *
  * @return array
  */
 public function buildBreadcrumbs($action, MenuItemInterface $menu = null)
 {
     if (isset($this->breadcrumbs[$action])) {
         return $this->breadcrumbs[$action];
     }
     if (!$menu) {
         $menu = $this->menuFactory->createItem('root');
     }
     $child = $menu->addChild($this->trans($this->getLabelTranslatorStrategy()->getLabel('dashboard', 'breadcrumb', 'link'), array(), 'SonataAdminBundle'), array('uri' => $this->routeGenerator->generate('sonata_admin_dashboard')));
     $child = $child->addChild($this->trans($this->getLabelTranslatorStrategy()->getLabel(sprintf('%s_list', $this->getClassnameLabel()), 'breadcrumb', 'link')), array('uri' => $this->generateUrl('list')));
     $childAdmin = $this->getCurrentChildAdmin();
     if ($childAdmin) {
         $id = $this->request->get($this->getIdParameter());
         $child = $child->addChild((string) $this->getSubject(), array('uri' => $this->generateUrl('edit', array('id' => $id))));
         return $childAdmin->buildBreadcrumbs($action, $child);
     } elseif ($this->isChild()) {
         if ($action != 'list') {
             $menu = $menu->addChild($this->trans($this->getLabelTranslatorStrategy()->getLabel(sprintf('%s_list', $this->getClassnameLabel()), 'breadcrumb', 'link')), array('uri' => $this->generateUrl('list')));
         }
         if ($action != 'create' && $this->hasSubject()) {
             $breadcrumbs = $menu->getBreadcrumbsArray((string) $this->getSubject());
         } else {
             $breadcrumbs = $menu->getBreadcrumbsArray($this->trans($this->getLabelTranslatorStrategy()->getLabel(sprintf('%s_%s', $this->getClassnameLabel(), $action), 'breadcrumb', 'link')));
         }
     } else {
         if ($action != 'list') {
             $breadcrumbs = $child->getBreadcrumbsArray($this->trans($this->getLabelTranslatorStrategy()->getLabel(sprintf('%s_%s', $this->getClassnameLabel(), $action), 'breadcrumb', 'link')));
         } else {
             $breadcrumbs = $child->getBreadcrumbsArray();
         }
     }
     // the generated $breadcrumbs contains an empty element
     array_shift($breadcrumbs);
     return $this->breadcrumbs[$action] = $breadcrumbs;
 }
Ejemplo n.º 2
0
 /**
  * Generates the breadcrumbs array.
  *
  * Note: the method will be called by the top admin instance (parent => child)
  *
  * @param string             $action
  * @param ItemInterface|null $menu
  *
  * @return array
  */
 public function buildBreadcrumbs($action, MenuItemInterface $menu = null)
 {
     if (isset($this->breadcrumbs[$action])) {
         return $this->breadcrumbs[$action];
     }
     if (!$menu) {
         $menu = $this->menuFactory->createItem('root');
         $menu = $menu->addChild($this->trans($this->getLabelTranslatorStrategy()->getLabel('dashboard', 'breadcrumb', 'link'), array(), 'SonataAdminBundle'), array('uri' => $this->routeGenerator->generate('sonata_admin_dashboard')));
     }
     $menu = $menu->addChild($this->trans($this->getLabelTranslatorStrategy()->getLabel(sprintf('%s_list', $this->getClassnameLabel()), 'breadcrumb', 'link')), array('uri' => $this->hasRoute('list') && $this->isGranted('LIST') ? $this->generateUrl('list') : null));
     $childAdmin = $this->getCurrentChildAdmin();
     if ($childAdmin) {
         $id = $this->request->get($this->getIdParameter());
         $menu = $menu->addChild($this->toString($this->getSubject()), array('uri' => $this->hasRoute('edit') && $this->isGranted('EDIT') ? $this->generateUrl('edit', array('id' => $id)) : null));
         return $childAdmin->buildBreadcrumbs($action, $menu);
     } elseif ($this->isChild()) {
         if ($action == 'list') {
             $menu->setUri(false);
         } elseif ($action != 'create' && $this->hasSubject()) {
             $menu = $menu->addChild($this->toString($this->getSubject()));
         } else {
             $menu = $menu->addChild($this->trans($this->getLabelTranslatorStrategy()->getLabel(sprintf('%s_%s', $this->getClassnameLabel(), $action), 'breadcrumb', 'link')));
         }
     } elseif ($action != 'list' && $this->hasSubject()) {
         $menu = $menu->addChild($this->toString($this->getSubject()));
     } elseif ($action != 'list') {
         $menu = $menu->addChild($this->trans($this->getLabelTranslatorStrategy()->getLabel(sprintf('%s_%s', $this->getClassnameLabel(), $action), 'breadcrumb', 'link')));
     }
     return $this->breadcrumbs[$action] = $menu;
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function generateMenuUrl($name, array $parameters = array(), $absolute = UrlGeneratorInterface::ABSOLUTE_PATH)
 {
     return $this->routeGenerator->generateMenuUrl($this, $name, $parameters, $absolute);
 }