private function addMenu(\Symforce\AdminBundle\Compiler\CacheObject\Menu $tree, \Knp\Menu\MenuItem $menu, $as_root = true) { if ($as_root) { $_menu = $menu; } else { $options = array('attributes' => array(), 'childrenAttributes' => array(), 'linkAttributes' => array(), 'extras' => array()); $label = $this->translator->trans($tree->getLabel(), array(), $tree->getDomain()); if ($tree->admin) { $admin_name = $tree->getName(); if (!$this->loadder->auth($admin_name, 'list')) { return; } $admin = $this->loadder->getAdminByName($admin_name); $options['uri'] = $admin->path('list'); } else { if ($tree->getUrl()) { $options['uri'] = $tree->getUrl(); } else { if ($tree->getRouteName()) { $options['uri'] = $this->container->get('router')->generate($tree->getRouteName()); } else { $options['uri'] = 'javascript:alert(0)'; } } } if ($tree->hasChildren()) { if ($menu->isRoot()) { $options['attributes']['class'] = 'dropdown'; $options['extras']['caret'] = true; } else { $options['attributes']['class'] = 'dropdown-submenu'; } $options['childrenAttributes']['class'] = 'dropdown-menu bottom-down'; $options['linkAttributes']['class'] = 'dropdown-toggle'; $options['linkAttributes']['data-toggle'] = 'dropdown'; } if (!$menu->isRoot()) { if (null !== $tree->getDivider()) { if ($tree->getDivider()) { $options['extras']['after_divider'] = true; } else { $options['extras']['before_divider'] = true; } } } if (null !== $tree->getIcon()) { $options['extras']['icon'] = $tree->getIcon(); } $_menu = $menu->addChild($label, $options); } foreach ($tree->getChildren() as $child) { $this->addMenu($child, $_menu, false); } }
public function testMoveSampleMenuToNewRoot() { $newRoot = new TestMenuItem("newRoot", $this->getMock('Knp\Menu\FactoryInterface')); $newRoot->addChild($this->menu); $this->assertEquals(1, $this->menu->getLevel()); $this->assertEquals(2, $this->pt1->getLevel()); $this->assertSame($newRoot, $this->menu->getRoot()); $this->assertSame($newRoot, $this->pt1->getRoot()); $this->assertFalse($this->menu->isRoot()); $this->assertTrue($newRoot->isRoot()); $this->assertSame($newRoot, $this->menu->getParent()); }
private function active(\Knp\Menu\MenuItem $vm) { if (!$vm->isRoot()) { $vm->setExtra('active', true); $vm->setAttribute('class', 'active'); $this->active($vm->getParent()); } }