Example #1
0
 /**
  * Add a child to the menu
  *
  * @param KnpMenu $menu
  * @param Menu    $item
  */
 protected function addChild(KnpMenu $menu, Menu $item)
 {
     $name = $item->getName() . $item->getId();
     $options = array();
     $options['label'] = ucfirst($item->getName());
     $options['extras'] = array('safe_label' => true);
     if ($item->getContent()) {
         $options['extras']['content'] = $item->getContent();
     }
     if (!$item instanceof MenuGroup) {
         if ($uri = $item->getLink()) {
             $options['uri'] = $uri;
         } elseif ($content = $item->getContent()) {
             $options['route'] = '_content';
             $slug = $content->getSlug();
             if (substr($slug, -6) == '/index') {
                 $slug = rtrim($slug, "index");
             }
             $options['routeParameters'] = ['slug' => $slug];
         }
     } else {
         $options['uri'] = '';
     }
     $menu->addChild($name, $options);
     if ($item->hasChildren()) {
         $menu[$name]->setChildrenAttribute('class', 'sub-nav');
         foreach ($item->getChildren() as $child) {
             $this->addChild($menu[$name], $child);
         }
     }
 }
Example #2
0
 public function testSort()
 {
     $menu = new Menu();
     $sort = 3;
     $expected = $sort;
     $menu->setSort($sort);
     $actual = $menu->getSort();
     $this->assertSame($expected, $actual);
 }
Example #3
0
 /**
  * @param  Menu $item
  * @return ArrayCollection
  */
 protected function getChildren(Menu $item)
 {
     $collection = new ArrayCollection();
     foreach ($this->getHierarchy() as $object) {
         if ($object->getParent() && $object->getParent()->getId() == $item->getId()) {
             $collection->add($object);
         }
     }
     return $collection;
 }