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 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 testName()
 {
     $menu = new Menu();
     $name = 'Some Name';
     $expected = $name;
     $menu->setName($name);
     $actual = $menu->getName();
     $this->assertSame($expected, $actual);
 }