/**
  * Renders a menu with the specified renderer.
  *
  * @param ItemInterface|string|array $menu
  *
  * @return string
  */
 public function getBreadcrumb($menu, $actions = null)
 {
     $menu = $this->helper->get($menu);
     $treeIterator = new \RecursiveIteratorIterator(new RecursiveItemIterator(new \ArrayIterator(array($menu))), \RecursiveIteratorIterator::SELF_FIRST);
     $iterator = new CurrentItemFilterIterator($treeIterator, $this->matcher);
     $manipulator = new MenuManipulator();
     foreach ($iterator as $item) {
         return $manipulator->getBreadcrumbsArray($item);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function render(ItemInterface $item, array $options = array())
 {
     $activeItem = $this->getActiveItem($item);
     if (!$activeItem) {
         return '';
     }
     $options = array_merge($this->defaultOptions, $options, array('currentClass' => 'active'));
     $breadcrumbArray = $this->manipulator->getBreadcrumbsArray($activeItem);
     $html = $this->renderList($breadcrumbArray, $options);
     if ($options['clear_matcher']) {
         $this->matcher->clear();
     }
     return $html;
 }
 /**
  * Render an array or KNP menu as foundation breadcrumb
  *
  * @param ItemInterface|string $menu
  * @param array $options
  * @return mixed
  */
 public function renderAsBreadcrumb($menu, array $options = array())
 {
     $options = array_merge(array('template' => $this->defaultTemplate), $options);
     if (!is_array($menu) && !$menu instanceof ItemInterface) {
         $path = array();
         if (is_array($menu)) {
             if (empty($menu)) {
                 throw new \InvalidArgumentException('The array cannot be empty');
             }
             $path = $menu;
             $menu = array_shift($path);
         }
         $menu = $this->menuHelper->get($menu, $path);
     }
     // Look into the menu to fetch the current item
     $treeIterator = new \RecursiveIteratorIterator(new RecursiveItemIterator(new \ArrayIterator(array($menu))), \RecursiveIteratorIterator::SELF_FIRST);
     $itemFilterIterator = new CurrentItemFilterIterator($treeIterator, $this->matcher);
     $itemFilterIterator->rewind();
     // Watch for a current item
     $current = $itemFilterIterator->current();
     $manipulator = new MenuManipulator();
     if ($current instanceof ItemInterface) {
         // Extract the items for the breadcrumb
         $breadcrumbs = $manipulator->getBreadcrumbsArray($current);
     } else {
         // Current item could not be located, we only send the first item
         $breadcrumbs = $manipulator->getBreadcrumbsArray($menu);
     }
     // Load the template if needed
     if (!$options['template'] instanceof \Twig_Template) {
         $options['template'] = $this->twig->loadTemplate($options['template']);
     }
     return $options['template']->renderBlock('root', array('breadcrumbs' => $breadcrumbs, 'options' => $options));
 }
Exemple #4
0
 /**
  * Main page top menu
  *
  * @param Request $request
  *
  * @return \Knp\Menu\MenuItem
  */
 public function createMainMenu(Request $request)
 {
     $menu = $this->factory->createItem('root');
     $menu->setUri($request->getRequestUri());
     $menu->setAttribute('class', 'nav');
     $menuManipulator = new MenuManipulator();
     if ($request->getPathInfo() != '/') {
         $item = $menu->addChild('← На главную', array('route' => 'homepage'));
         $menuManipulator->moveToFirstPosition($item);
     }
     $menu->addChild('О Frameworks Days', array('route' => 'page_show', 'routeParameters' => array('slug' => 'about')));
     $menu->addChild('События', array('route' => 'events'));
     $menu->addChild('Контакты', array('route' => 'page_show', 'routeParameters' => array('slug' => 'contacts')));
     $menu->addChild('Партнеры', array('route' => 'partners_page'));
     return $menu;
 }
 /**
  * Return breadcrumb array
  *
  * @param $menuName
  * @param $item
  * @param bool $isInverse
  * @return array
  */
 public function getBreadcrumbArray($menuName, $item, $isInverse = true)
 {
     $manipulator = new MenuManipulator();
     $breadcrumbs = $manipulator->getBreadcrumbsArray($item);
     if ($breadcrumbs[0]['label'] == $menuName) {
         unset($breadcrumbs[0]);
     }
     if (!$isInverse) {
         $breadcrumbs = array_reverse($breadcrumbs);
     }
     return $breadcrumbs;
 }
 public function testToArrayWithoutChildren()
 {
     $menu = $this->createMenu();
     $menu->addChild('jack', array('uri' => 'http://php.net', 'linkAttributes' => array('title' => 'php'), 'display' => false));
     $menu->addChild('joe', array('attributes' => array('class' => 'leaf'), 'label' => 'test', 'labelAttributes' => array('class' => 'center'), 'displayChildren' => false));
     $manipulator = new MenuManipulator();
     $this->assertEquals(array('name' => 'test_menu', 'label' => 'test_menu', 'uri' => 'homepage', 'attributes' => array(), 'labelAttributes' => array(), 'linkAttributes' => array(), 'childrenAttributes' => array(), 'extras' => array(), 'display' => true, 'displayChildren' => true, 'current' => null), $manipulator->toArray($menu, 0));
 }