/**
  * 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));
 }
 /**
  * Renders a bootstrap conform page tree menu
  *
  * @param ItemInterface $menu
  * @param array $options
  *
  * @return string
  */
 public function renderBootstrap($menu, array $options = [])
 {
     // Set default values
     $options = array_merge(["template" => "@BecklynPageTree/Menu/bootstrap.html.twig", "currentClass" => "active", "ancestorClass" => "active", "hoverDropdown" => true, "listClass" => "navbar-nav"], $options);
     // force twig renderer, because we only provide a twig template
     $helper = new Helper($this->rendererProvider, $this->menuProvider);
     return $helper->render($menu, $options, "twig");
 }
Esempio n. 3
0
 /**
  * Retrieves the current item.
  *
  * @param ItemInterface|string $menu
  *
  * @return ItemInterface
  */
 public function getCurrentItem($menu)
 {
     $rootItem = $this->helper->get($menu);
     $currentItem = $this->retrieveCurrentItem($rootItem);
     if (null === $currentItem) {
         $currentItem = $rootItem;
     }
     return $currentItem;
 }
 /**
  * @param ItemInterface|string $menu
  * @param array                $path
  * @param array                $options
  *
  * @return ItemInterface[]
  *
  * @throws \BadMethodCallException   when there is no menu provider and the menu is given by name
  * @throws \LogicException
  * @throws \InvalidArgumentException when the path is invalid
  */
 public function getCurrents($menu, array $path = array(), array $options = array())
 {
     $menu = $this->menuHelper->get($menu, $path, $options);
     $menuIterator = new \RecursiveIteratorIterator(new RecursiveItemIterator(new \ArrayIterator([$menu])), \RecursiveIteratorIterator::SELF_FIRST);
     $currents = [];
     foreach ($menuIterator as $item) {
         /** @var $item ItemInterface */
         if ($this->matcher->isCurrent($item)) {
             $currents[] = $item->getName();
         }
     }
     return $currents;
 }
 /**
  */
 public function testBuildWithOptionsAndRenderer()
 {
     $menuConfig = $this->getMenuConfigYamlArray();
     $this->helper->expects($this->once())->method('render')->with($this->containsOnlyInstancesOf('Knp\\Menu\\MenuItem'), $this->equalTo(['type' => 'some_menu']), $this->equalTo('some_renderer'))->will($this->returnValue('menu'));
     $this->container->setParameter('oro_menu_config', $menuConfig);
     $this->menuExtension->render(['navbar', 'user_user_show'], ['type' => 'some_menu'], 'some_renderer');
 }
Esempio n. 6
0
 public function renderFull()
 {
     $bundles = $this->kernel->getBundles();
     $return = '';
     foreach ($bundles as $bundle) {
         $bundlePath = $bundle->getPath();
         $bundleNamespace = $bundle->getNamespace();
         $bundleAlias = $bundle->getName();
         if (file_exists($bundlePath . '/Menu/Builder.php')) {
             $classFullName = $bundleNamespace . '\\' . $this->className;
             if (method_exists($classFullName, $this->methodName)) {
                 $return .= $this->helper->render($bundleAlias . ':Builder:' . $this->methodName, array('firstClass' => 'teste_primeira_classe', 'currentClass' => 'active'));
             }
         }
     }
     return $return;
 }
Esempio n. 7
0
 /**
  * Renders a menu with the specified renderer.
  *
  * @param \Knp\Menu\ItemInterface|string|array $menu
  * @param array                                $options
  * @param string                               $renderer
  *
  * @return string
  */
 public function render($menu, array $options = [], $renderer = null)
 {
     if (null === $renderer) {
         $renderer = $menu;
     }
     $options['menu'] = $menu;
     return $this->helper->render($menu, $options, $renderer);
 }
 /**
  * @param Menu $menu
  * @param array $options
  * @return string
  */
 public function prepareMenu(Menu $menu = null, array $options = [])
 {
     $html = '';
     if ($menu) {
         $this->prepareItems($menu, $options);
         $html = $this->helper->render($menu, $options);
     }
     return $html;
 }
 /**
  * Renders the Menu with the specified renderer.
  *
  * @param \Knp\Menu\ItemInterface|string|array $menu
  * @param array $options
  * @param string $renderer
  *
  * @throws \InvalidArgumentException
  * @return string
  */
 public function renderMenu($menu, array $options = array(), $renderer = null)
 {
     $options = array_merge(array('template' => $this->menuTemplate, 'currentClass' => 'active', 'ancestorClass' => 'active', 'allow_safe_labels' => true), $options);
     if (!$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->helper->get($menu, $path);
     }
     $menu = $this->helper->get($menu, array(), $options);
     if (isset($options['automenu'])) {
         $this->getMenuConverter()->convert($menu, $options);
     }
     return $this->helper->render($menu, $options, $renderer);
 }
Esempio n. 10
0
 /**
  * Renders a menu with the specified renderer.
  *
  * @param ItemInterface|string|array $menu
  * @param array                      $options
  * @param string                     $renderer
  *
  * @throws \InvalidArgumentException
  * @return string
  */
 public function render($menu, array $options = array(), $renderer = null)
 {
     if (!$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->getMenu($menu, $path, $options);
     }
     $menu = $this->filterUnallowedItems($menu);
     $menuType = $menu->getExtra('type');
     // rewrite config options with args
     if (!empty($menuType) && !empty($this->menuConfiguration['templates'][$menuType])) {
         $options = array_replace_recursive($this->menuConfiguration['templates'][$menuType], $options);
     }
     return $this->helper->render($menu, $options, $renderer);
 }
 /**
  * Renders a menu with the specified renderer.
  *
  * @param ItemInterface|string|array $menu
  * @param array                      $options
  * @param string                     $renderer
  *
  * @throws \InvalidArgumentException
  * @return string
  */
 public function render($menu, array $options = array(), $renderer = null)
 {
     if (!$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->getMenu($menu, $path, $options);
     }
     $menuType = $menu->getExtra('type');
     if (!empty($menuType)) {
         $menuConfig = $this->container->getParameter('oro_menu_config');
         if (!empty($menuConfig['templates'][$menuType])) {
             // rewrite config options with args
             $options = array_replace_recursive($menuConfig['templates'][$menuType], $options);
         }
     }
     return $this->helper->render($menu, $options, $renderer);
 }
 /**
  * Get KnpMenu
  *
  * @param Request $request
  *
  * @return ItemInterface
  */
 public function getKnpMenu(Request $request = null)
 {
     $menuFactory = new MenuFactory();
     $menu = $menuFactory->createItem('root')->setExtra('request', $request);
     foreach ($this->pool->getAdminGroups() as $name => $group) {
         // Check if the menu group is built by a menu provider
         if (isset($group['provider'])) {
             $subMenu = $this->knpHelper->get($group['provider']);
             $menu->addChild($subMenu)->setAttributes(array('icon' => $group['icon'], 'label_catalogue' => $group['label_catalogue']))->setExtra('roles', $group['roles']);
             continue;
         }
         // The menu group is built by config
         $menu->addChild($name, array('label' => $group['label']))->setAttributes(array('icon' => $group['icon'], 'label_catalogue' => $group['label_catalogue']))->setExtra('roles', $group['roles']);
         foreach ($group['items'] as $item) {
             if (array_key_exists('admin', $item) && $item['admin'] != null) {
                 $admin = $this->pool->getInstance($item['admin']);
                 // skip menu item if no `list` url is available or user doesn't have the LIST access rights
                 if (!$admin->hasRoute('list') || !$admin->isGranted('LIST')) {
                     continue;
                 }
                 $label = $admin->getLabel();
                 $route = $admin->generateUrl('list');
                 $translationDomain = $admin->getTranslationDomain();
             } else {
                 $label = $item['label'];
                 $route = $this->router->generate($item['route'], $item['route_params']);
                 $translationDomain = $group['label_catalogue'];
                 $admin = null;
             }
             $menu[$name]->addChild($label, array('uri' => $route))->setExtra('translationdomain', $translationDomain)->setExtra('admin', $admin);
         }
         if (0 === count($menu[$name]->getChildren())) {
             $menu->removeChild($name);
         }
     }
     return $menu;
 }
Esempio n. 13
0
 public function testBreadcrumbsArray()
 {
     $menu = $this->getMock('Knp\\Menu\\ItemInterface');
     $manipulator = $this->getMock('Knp\\Menu\\Util\\MenuManipulator');
     $manipulator->expects($this->any())->method('getBreadcrumbsArray')->with($menu)->will($this->returnValue(array('A', 'B')));
     $helper = new Helper($this->getMock('Knp\\Menu\\Renderer\\RendererProviderInterface'), null, $manipulator);
     $this->assertEquals(array('A', 'B'), $helper->getBreadcrumbsArray($menu));
 }
Esempio n. 14
0
 /**
  * @expectedException InvalidArgumentException
  * @expectedExceptionMessage The array cannot be empty
  */
 public function testRenderByEmptyPath()
 {
     $helper = new Helper($this->getMock('Knp\Menu\Renderer\RendererProviderInterface'));
     $helper->render(array());
 }