Пример #1
0
 public function testNavOverwrite()
 {
     $defaults = Navigation::getDefaults();
     Hash::merge($defaults, array('title' => 'Permissions', 'url' => array('admin' => true, 'plugin' => 'acl', 'controller' => 'acl_permissions', 'action' => 'index'), 'weight' => 30));
     $item = array('title' => 'Permissions', 'url' => array('admin' => true, 'plugin' => 'acl_extras', 'controller' => 'acl_extras_permissions', 'action' => 'index'), 'weight' => 30);
     Navigation::add('users.children.permissions', $item);
     $items = Navigation::items();
     $expected = Hash::merge($defaults, array('title' => 'Permissions', 'url' => array('admin' => true, 'plugin' => 'acl_extras', 'controller' => 'acl_extras_permissions', 'action' => 'index'), 'weight' => 30));
     $this->assertEquals($expected, $items['users']['children']['permissions']);
 }
Пример #2
0
 /**
  * [_render description]
  * @param [type] $path [description]
  * @param [type] $attrs [description]
  * @return [type]
  */
 protected function _render($nav)
 {
     extract($nav);
     $items = Navigation::order(Navigation::items($path));
     if (empty($items)) {
         return false;
     }
     $defaults = array($this->_tag => array(), $this->_tags[$this->_tag] => array(), 'a' => array());
     $list = array();
     foreach ($items as $key => $options) {
         $title = Inflector::humanize($key);
         extract($options);
         $htmlAttributes = Hash::merge($defaults, $htmlAttributes);
         Reveal::addRule('Page.current', array('self', '__isPageCurrent'), Router::normalize($url));
         if (Reveal::is('Page.current')) {
             $class = 'active';
             if (!empty($htmlAttributes[$this->_tags[$this->_tag]]['class'])) {
                 $class = $htmlAttributes[$this->_tags[$this->_tag]]['class'] . ' ' . $class;
             }
             $htmlAttributes = Hash::merge($htmlAttributes, array($this->_tags[$this->_tag] => compact('class')));
         }
         if (method_exists($this->Html, 'icon') && !empty($icon) && count(explode(' ', $icon)) == 1) {
             $icon = $this->Html->icon($icon);
         }
         $title = $icon . $title;
         // Link-ify item's title when it does not match the current page.
         if (!empty($url)) {
             // Allow for link tag customization using `HtmlHelper::loadConfig()`.
             $configPath = dirname(__FILE__) . DS . 'Navigation' . DS;
             $reset = false;
             if (!empty($htmlAttributes['a']['tag'])) {
                 $this->Html->loadConfig($htmlAttributes['a']['tag'], $configPath);
                 $reset = true;
                 unset($htmlAttributes['a']['tag']);
             }
             if (isset($url['prefix']) && false === $url['prefix'] && !empty($this->_View->request->prefix)) {
                 $url[$this->_View->request->prefix] = false;
             }
             if (is_array($url) && !isset($url['plugin'])) {
                 $url['plugin'] = null;
             }
             $title = $this->Html->link($title, $url, $htmlAttributes['a'], $confirmMessage);
             $reset && $this->Html->loadConfig('reset', $configPath);
         }
         if (!empty($children)) {
             // if (!)$title = $this->Html->tag('span', $title, array('class' => 'title'));
             $title .= $this->_render(array('path' => "{$path}.{$key}.children", 'attrs' => $htmlAttributes[$this->_tag]));
         }
         $list[] = $this->Html->tag($this->_tags[$this->_tag], $title, $htmlAttributes[$this->_tags[$this->_tag]]);
     }
     return $this->Html->tag($this->_tag, implode('', $list), $attrs);
 }