From f517c0e87121219b8f75e2412b040ff0e83a1e8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Arellano?= Date: Tue, 21 Jul 2015 23:35:17 -0300 Subject: [PATCH 1/3] Allow add options to dropdown items --- src/View/Helper/BootstrapHtmlHelper.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/View/Helper/BootstrapHtmlHelper.php b/src/View/Helper/BootstrapHtmlHelper.php index 2632ea1..dca0128 100644 --- a/src/View/Helper/BootstrapHtmlHelper.php +++ b/src/View/Helper/BootstrapHtmlHelper.php @@ -316,9 +316,14 @@ public function dropdown (array $menu = [], array $options = []) { } $name = array_shift($action) ; $url = array_shift($action) ; + $li_options = ['role' => 'presentation']; + if (array_key_exists('_options', $action)) { + $li_options += $action['_options']; + unset($action['_options']); + } $action['role'] = 'menuitem' ; $action['tabindex'] = -1 ; - $output .= '
  • '.$this->link($name, $url, $action).'
  • '; + $output .= $this->tag('li', $this->link($name, $url, $action), $li_options); } } else { From 1dd82055f1250550df6aca538672bde627c552e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Arellano?= Date: Wed, 22 Jul 2015 00:33:57 -0300 Subject: [PATCH 2/3] Added navbarNav --- src/View/Helper/BootstrapHtmlHelper.php | 44 +++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/View/Helper/BootstrapHtmlHelper.php b/src/View/Helper/BootstrapHtmlHelper.php index dca0128..3e6099f 100644 --- a/src/View/Helper/BootstrapHtmlHelper.php +++ b/src/View/Helper/BootstrapHtmlHelper.php @@ -338,6 +338,50 @@ public function dropdown (array $menu = [], array $options = []) { return $this->tag($tag, $output, $options) ; } + public function navbarNav(array $menu = [], array $options = []) { + $output = ''; + foreach ($menu as $item => $submenu) { + if ($item === 'divider' || (is_array($item) && $item[0] === 'divider')) { + $output .= '' ; + } + elseif (is_array($submenu)) { + $dropdown_options = ['tag' => 'ul']; + $link_options = [ + 'data-toggle' => 'dropdown', + 'role' => 'button', + 'aria-haspopup' => 'true', + 'aria-expanded' => 'false' + ]; + $li_options = []; + if (array_key_exists('_options', $submenu) && is_array($submenu['_options'])) { + if (array_key_exists('dropdown', $submenu['_options'])) { + $dropdown_options += $submenu['_options']['dropdown']; + $dropdown_options = $this->addClass($dropdown_options, 'dropdown-menu'); + } + if (array_key_exists('link', $submenu['_options'])) { + $link_options += $submenu['_options']['link']; + $link_options = $this->addClass($link_options, 'dropdown-toggle'); + } + if (array_key_exists('li', $submenu['_options'])) { + $li_options += $submenu['_options']['li']; + } + unset($submenu['_options']); + } + + $output .= $this->tag( + 'li', + $this->link($item, '#', $link_options).$this->dropdown($submenu, $dropdown_options), + $li_options + ); + } + else { + $output .= '
  • '.$submenu.'
  • ' ; + } + } + $options = ['tag' => 'ul', 'class' => 'nav navbar-nav'] + $options; + return $this->tag($options['tag'], $output, $options); + } + /** * Create a formatted collection of elements while * maintaining proper bootstrappy markup. Useful when From 4cf235c346c3d134ea5ca4cdc3c5ed26533f8f10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Arellano?= Date: Wed, 22 Jul 2015 00:40:57 -0300 Subject: [PATCH 3/3] Added option to manage carets in navbarNav --- src/View/Helper/BootstrapHtmlHelper.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/View/Helper/BootstrapHtmlHelper.php b/src/View/Helper/BootstrapHtmlHelper.php index 3e6099f..ba4c785 100644 --- a/src/View/Helper/BootstrapHtmlHelper.php +++ b/src/View/Helper/BootstrapHtmlHelper.php @@ -352,7 +352,7 @@ public function navbarNav(array $menu = [], array $options = []) { 'aria-haspopup' => 'true', 'aria-expanded' => 'false' ]; - $li_options = []; + $li_options = ['caret' => true]; if (array_key_exists('_options', $submenu) && is_array($submenu['_options'])) { if (array_key_exists('dropdown', $submenu['_options'])) { $dropdown_options += $submenu['_options']['dropdown']; @@ -368,9 +368,20 @@ public function navbarNav(array $menu = [], array $options = []) { unset($submenu['_options']); } + $caret = ''; + if ($li_options['caret'] === TRUE) { + $caret = ' '; + } elseif ($li_options['caret'] === FALSE) { + $caret = ''; + } else { + $caret = $li_options['caret']; + } + unset($li_options['caret']); + $output .= $this->tag( 'li', - $this->link($item, '#', $link_options).$this->dropdown($submenu, $dropdown_options), + $this->link($item.$caret, '#', $link_options). + $this->dropdown($submenu, $dropdown_options), $li_options ); }