예제 #1
0
 protected function addItem(MenuItem $root, $config)
 {
     foreach ($config['roles'] as $role) {
         if (!$this->security->isGranted($role)) {
             return null;
         }
     }
     $name = $config['label'];
     $label = isset($config['icon']) ? $config['icon'] . ' ' : ' ';
     $label .= "<span class='sidebar-title'>" . $config['label'] . "</span>";
     $label .= isset($config['items']) && count($config['items']) ? '<span class="caret"></span>' : '';
     $options = array('label' => $label, 'extras' => array('safe_label' => true));
     if ('#' == $config['route']) {
         $options['uri'] = '#';
     } elseif ($config['route']) {
         $options['route'] = $config['route'];
     }
     if ($root->getChild($name)) {
         $name .= microtime();
     }
     $MenuItem = $root->addChild($name, $options);
     if (isset($config['class'])) {
         $MenuItem->setAttribute('class', $config['class']);
     }
     if (isset($config['items'])) {
         foreach ($config['items'] as $item) {
             $this->addItem($MenuItem, $item);
         }
         if ($root->getLevel()) {
             $root->setChildrenAttribute('class', 'nav sub-nav');
             $root->setLinkAttribute('class', 'accordion-toggle');
         }
     }
 }
예제 #2
0
    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());
    }