public function testHasChildren() { $menu = new Menu(); $expected = false; $actual = $menu->hasChildren(); $this->assertSame($expected, $actual); }
/** * 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); } } }