Ejemplo n.º 1
0
 public function testUpdateChildAfterRename()
 {
     $this->pt1->setName('Temp name');
     $this->assertSame($this->pt1, $this->menu->getChild('Temp name'));
     $this->assertEquals(array('Temp name', 'Parent 2'), array_keys($this->menu->getChildren()));
     $this->assertNull($this->menu->getChild('Parent 1'));
 }
Ejemplo n.º 2
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');
         }
     }
 }