Bootstrap\View\Helper\BootstrapHtmlHelper::dropdown PHP Method

dropdown() public method

Create & return a twitter bootstrap dropdown menu.
public dropdown ( array $menu = [], array $options = [] )
$menu array HTML tags corresponding to menu options (which will be wrapped into
  • tag). To add separator, pass 'divider'.
  • $options array Attributes for the wrapper (change it with tag)
        public function dropdown(array $menu = [], array $options = [])
        {
            $output = '';
            foreach ($menu as $action) {
                if ($action === 'divider' || is_array($action) && $action[0] === 'divider') {
                    $output .= '<li role="presentation" class="divider"></li>';
                } elseif (is_array($action)) {
                    if ($action[0] === 'header') {
                        $output .= '<li role="presentation" class="dropdown-header">' . $action[1] . '</li>';
                    } else {
                        if ($action[0] === 'link') {
                            array_shift($action);
                            // Remove first cell
                        }
                        $name = array_shift($action);
                        $url = array_shift($action);
                        $action['role'] = 'menuitem';
                        $action['tabindex'] = -1;
                        $output .= '<li role="presentation">' . $this->link($name, $url, $action) . '</li>';
                    }
                } else {
                    $output .= '<li role="presentation">' . $action . '</li>';
                }
            }
            $options = $this->addClass($options, 'dropdown-menu');
            $options['role'] = 'menu';
            $options += ['tag' => 'ul'];
            $tag = $options['tag'];
            unset($options['tag']);
            return $this->tag($tag, $output, $options);
        }