From a48f568f465216dd8f593c78cc34956158e0710d Mon Sep 17 00:00:00 2001 From: Konstantin Sopin Date: Mon, 30 Dec 2013 10:48:45 +0300 Subject: [PATCH 1/7] Create css2.html for test LiActiveClass method --- test/Helper/Navigation/_files/expected/menu/css2.html | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 test/Helper/Navigation/_files/expected/menu/css2.html diff --git a/test/Helper/Navigation/_files/expected/menu/css2.html b/test/Helper/Navigation/_files/expected/menu/css2.html new file mode 100644 index 00000000..6a8b5bea --- /dev/null +++ b/test/Helper/Navigation/_files/expected/menu/css2.html @@ -0,0 +1,11 @@ + From 68340770dfb61bb42d691af855a85f94a02ec0b7 Mon Sep 17 00:00:00 2001 From: Konstantin Sopin Date: Mon, 30 Dec 2013 10:52:05 +0300 Subject: [PATCH 2/7] Add test for munu liActiveClass method --- test/Helper/Navigation/MenuTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/Helper/Navigation/MenuTest.php b/test/Helper/Navigation/MenuTest.php index 935e7ca1..b0d6edf6 100644 --- a/test/Helper/Navigation/MenuTest.php +++ b/test/Helper/Navigation/MenuTest.php @@ -169,6 +169,13 @@ public function testSetUlCssClass() $expected = $this->_getExpected('menu/css.html'); $this->assertEquals($expected, $this->_helper->render($this->_nav2)); } + + public function testSetLiActiveCssClass() + { + $this->_helper->setLiActiveClassClass('activated'); + $expected = $this->_getExpected('menu/css2.html'); + $this->assertEquals($expected, $this->_helper->render($this->_nav2)); + } public function testOptionEscapeLabelsAsTrue() { From 696b58ac3815dd0b2191c87ad4c78c95c45a5bd1 Mon Sep 17 00:00:00 2001 From: Konstantin Sopin Date: Tue, 31 Dec 2013 12:42:04 +0300 Subject: [PATCH 3/7] Add missed getLiActiveClass() method --- src/Helper/Navigation/Menu.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Helper/Navigation/Menu.php b/src/Helper/Navigation/Menu.php index 9f6737ba..5b9bcd87 100644 --- a/src/Helper/Navigation/Menu.php +++ b/src/Helper/Navigation/Menu.php @@ -716,6 +716,16 @@ public function setUlClass($ulClass) return $this; } + + /** + * Returns CSS class to use for the first 'ul' element when rendering + * + * @return string + */ + public function getUlClass() + { + return $this->ulClass; + } /** * Sets CSS class to use for the active 'li' element when rendering @@ -731,14 +741,14 @@ public function setLiActiveClass($liActiveClass) return $this; } - + /** - * Returns CSS class to use for the first 'ul' element when rendering + * Returns CSS class to use for the active 'li' element when rendering * * @return string */ - public function getUlClass() + public function getLiActiveClass() { - return $this->ulClass; + return $this->liActiveClass; } } From 937ad2464bd5950249173e0955dca8f3fd698ca9 Mon Sep 17 00:00:00 2001 From: Konstantin Sopin Date: Tue, 31 Dec 2013 14:19:19 +0300 Subject: [PATCH 4/7] Add liActiveClass using recommendations --- src/Helper/Navigation/Menu.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Helper/Navigation/Menu.php b/src/Helper/Navigation/Menu.php index 5b9bcd87..ab5213be 100644 --- a/src/Helper/Navigation/Menu.php +++ b/src/Helper/Navigation/Menu.php @@ -117,6 +117,7 @@ public function render($container = null) * * @param AbstractContainer $container container to render * @param string $ulClass CSS class for first UL + * @param string $liActiveClass CSS class for active LI * @param string $indent initial indentation * @param int|null $minDepth minimum depth * @param int|null $maxDepth maximum depth @@ -127,6 +128,7 @@ public function render($container = null) protected function renderDeepestMenu( AbstractContainer $container, $ulClass, + $liActiveClass, $indent, $minDepth, $maxDepth, @@ -162,7 +164,7 @@ protected function renderDeepestMenu( $liClasses = array(); // Is page active? if ($subPage->isActive(true)) { - $liClasses[] = $this->liActiveClass; + $liClasses[] = $liActiveClass; } // Add CSS class from page to
  • if ($addClassToListItem && $subPage->getClass()) { @@ -208,6 +210,7 @@ public function renderMenu($container = null, array $options = array()) if ($options['onlyActiveBranch'] && !$options['renderParents']) { $html = $this->renderDeepestMenu($container, $options['ulClass'], + $options['liActiveClass'], $options['indent'], $options['minDepth'], $options['maxDepth'], @@ -217,6 +220,7 @@ public function renderMenu($container = null, array $options = array()) } else { $html = $this->renderNormalMenu($container, $options['ulClass'], + $options['liActiveClass'], $options['indent'], $options['minDepth'], $options['maxDepth'], @@ -234,6 +238,7 @@ public function renderMenu($container = null, array $options = array()) * * @param AbstractContainer $container container to render * @param string $ulClass CSS class for first UL + * @param string $liActiveClass CSS class for active LI * @param string $indent initial indentation * @param int|null $minDepth minimum depth * @param int|null $maxDepth maximum depth @@ -245,6 +250,7 @@ public function renderMenu($container = null, array $options = array()) protected function renderNormalMenu( AbstractContainer $container, $ulClass, + $liActiveClass, $indent, $minDepth, $maxDepth, @@ -331,7 +337,7 @@ protected function renderNormalMenu( $liClasses = array(); // Is page active? if ($isActive) { - $liClasses[] = $this->liActiveClass; + $liClasses[] = $liActiveClass; } // Add CSS class from page to
  • if ($addClassToListItem && $page->getClass()) { @@ -441,6 +447,10 @@ public function renderPartial($container = null, $partial = null) * use for UL element. Default * is to use the value from * {@link getUlClass()}. + * @param string $liActiveClass [optional] CSS class to + * use for UL element. Default + * is to use the value from + * {@link getUlClass()}. * @param string|int $indent [optional] indentation as * a string or number of * spaces. Default is to use @@ -451,11 +461,13 @@ public function renderPartial($container = null, $partial = null) public function renderSubMenu( AbstractContainer $container = null, $ulClass = null, + $liActiveClass = null, $indent = null ) { return $this->renderMenu($container, array( 'indent' => $indent, 'ulClass' => $ulClass, + 'liActiveClass' => $liActiveClass, 'minDepth' => null, 'maxDepth' => null, 'onlyActiveBranch' => true, @@ -544,6 +556,12 @@ protected function normalizeOptions(array $options = array()) } else { $options['ulClass'] = $this->getUlClass(); } + + if (isset($options['liActiveClass']) && $options['liActiveClass'] !== null) { + $options['liActiveClass'] = (string) $options['liActiveClass']; + } else { + $options['liActiveClass'] = $this->getLiActiveClass(); + } if (array_key_exists('minDepth', $options)) { if (null !== $options['minDepth']) { From 2b7ad0f8c44ba99bbb1e14a6d81728bcfceb146a Mon Sep 17 00:00:00 2001 From: Konstantin Sopin Date: Tue, 31 Dec 2013 14:50:04 +0300 Subject: [PATCH 5/7] fix copy-paste error --- test/Helper/Navigation/MenuTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Helper/Navigation/MenuTest.php b/test/Helper/Navigation/MenuTest.php index b0d6edf6..3be53625 100644 --- a/test/Helper/Navigation/MenuTest.php +++ b/test/Helper/Navigation/MenuTest.php @@ -172,7 +172,7 @@ public function testSetUlCssClass() public function testSetLiActiveCssClass() { - $this->_helper->setLiActiveClassClass('activated'); + $this->_helper->setLiActiveClass('activated'); $expected = $this->_getExpected('menu/css2.html'); $this->assertEquals($expected, $this->_helper->render($this->_nav2)); } From a23bd809e158c443b5b4375d25f4a182404dd042 Mon Sep 17 00:00:00 2001 From: Konstantin Sopin Date: Wed, 1 Jan 2014 21:28:47 +0300 Subject: [PATCH 6/7] Move new variable to end of the list --- src/Helper/Navigation/Menu.php | 69 +++++++++++++++++----------------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/src/Helper/Navigation/Menu.php b/src/Helper/Navigation/Menu.php index ab5213be..0541e4e9 100644 --- a/src/Helper/Navigation/Menu.php +++ b/src/Helper/Navigation/Menu.php @@ -116,24 +116,24 @@ public function render($container = null) * from {@link renderMenu()}) * * @param AbstractContainer $container container to render - * @param string $ulClass CSS class for first UL - * @param string $liActiveClass CSS class for active LI + * @param string $ulClass CSS class for first UL * @param string $indent initial indentation * @param int|null $minDepth minimum depth * @param int|null $maxDepth maximum depth * @param bool $escapeLabels Whether or not to escape the labels * @param bool $addClassToListItem Whether or not page class applied to
  • element + * @param string $liActiveClass CSS class for active LI * @return string */ protected function renderDeepestMenu( AbstractContainer $container, $ulClass, - $liActiveClass, $indent, $minDepth, $maxDepth, $escapeLabels, - $addClassToListItem + $addClassToListItem, + $liActiveClass ) { if (!$active = $this->findActive($container, $minDepth - 1, $maxDepth)) { return ''; @@ -210,23 +210,23 @@ public function renderMenu($container = null, array $options = array()) if ($options['onlyActiveBranch'] && !$options['renderParents']) { $html = $this->renderDeepestMenu($container, $options['ulClass'], - $options['liActiveClass'], $options['indent'], $options['minDepth'], $options['maxDepth'], $options['escapeLabels'], - $options['addClassToListItem'] + $options['addClassToListItem'], + $options['liActiveClass'] ); } else { $html = $this->renderNormalMenu($container, $options['ulClass'], - $options['liActiveClass'], $options['indent'], $options['minDepth'], $options['maxDepth'], $options['onlyActiveBranch'], $options['escapeLabels'], - $options['addClassToListItem'] + $options['addClassToListItem'], + $options['liActiveClass'] ); } @@ -238,25 +238,25 @@ public function renderMenu($container = null, array $options = array()) * * @param AbstractContainer $container container to render * @param string $ulClass CSS class for first UL - * @param string $liActiveClass CSS class for active LI * @param string $indent initial indentation * @param int|null $minDepth minimum depth * @param int|null $maxDepth maximum depth * @param bool $onlyActive render only active branch? * @param bool $escapeLabels Whether or not to escape the labels * @param bool $addClassToListItem Whether or not page class applied to
  • element + * @param string $liActiveClass CSS class for active LI * @return string */ protected function renderNormalMenu( AbstractContainer $container, $ulClass, - $liActiveClass, $indent, $minDepth, $maxDepth, $onlyActive, $escapeLabels, - $addClassToListItem + $addClassToListItem, + $liActiveClass ) { $html = ''; @@ -435,45 +435,46 @@ public function renderPartial($container = null, $partial = null) * 'minDepth' => null, * 'maxDepth' => null, * 'onlyActiveBranch' => true, - * 'renderParents' => false + * 'renderParents' => false, + * 'liActiveClass' => $liActiveClass * )); * * - * @param AbstractContainer $container [optional] container to - * render. Default is to render - * the container registered in - * the helper. - * @param string $ulClass [optional] CSS class to - * use for UL element. Default - * is to use the value from - * {@link getUlClass()}. + * @param AbstractContainer $container [optional] container to + * render. Default is to render + * the container registered in + * the helper. + * @param string $ulClass [optional] CSS class to + * use for UL element. Default + * is to use the value from + * {@link getUlClass()}. + * @param string|int $indent [optional] indentation as + * a string or number of + * spaces. Default is to use + * the value retrieved from + * {@link getIndent()}. * @param string $liActiveClass [optional] CSS class to * use for UL element. Default * is to use the value from * {@link getUlClass()}. - * @param string|int $indent [optional] indentation as - * a string or number of - * spaces. Default is to use - * the value retrieved from - * {@link getIndent()}. * @return string */ public function renderSubMenu( AbstractContainer $container = null, $ulClass = null, - $liActiveClass = null, - $indent = null + $indent = null, + $liActiveClass = null ) { return $this->renderMenu($container, array( 'indent' => $indent, 'ulClass' => $ulClass, - 'liActiveClass' => $liActiveClass, 'minDepth' => null, 'maxDepth' => null, 'onlyActiveBranch' => true, 'renderParents' => false, 'escapeLabels' => true, 'addClassToListItem' => false, + 'liActiveClass' => $liActiveClass )); } @@ -557,12 +558,6 @@ protected function normalizeOptions(array $options = array()) $options['ulClass'] = $this->getUlClass(); } - if (isset($options['liActiveClass']) && $options['liActiveClass'] !== null) { - $options['liActiveClass'] = (string) $options['liActiveClass']; - } else { - $options['liActiveClass'] = $this->getLiActiveClass(); - } - if (array_key_exists('minDepth', $options)) { if (null !== $options['minDepth']) { $options['minDepth'] = (int) $options['minDepth']; @@ -598,6 +593,12 @@ protected function normalizeOptions(array $options = array()) if (!isset($options['addClassToListItem'])) { $options['addClassToListItem'] = $this->getAddClassToListItem(); } + + if (isset($options['liActiveClass']) && $options['liActiveClass'] !== null) { + $options['liActiveClass'] = (string) $options['liActiveClass']; + } else { + $options['liActiveClass'] = $this->getLiActiveClass(); + } return $options; } From c17d4e48ad590e6f4b843fb0608d6498da1e13d8 Mon Sep 17 00:00:00 2001 From: Konstantin Sopin Date: Wed, 1 Jan 2014 21:43:54 +0300 Subject: [PATCH 7/7] Drop spaces --- src/Helper/Navigation/Menu.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Helper/Navigation/Menu.php b/src/Helper/Navigation/Menu.php index 0541e4e9..7ef334bf 100644 --- a/src/Helper/Navigation/Menu.php +++ b/src/Helper/Navigation/Menu.php @@ -116,7 +116,7 @@ public function render($container = null) * from {@link renderMenu()}) * * @param AbstractContainer $container container to render - * @param string $ulClass CSS class for first UL + * @param string $ulClass CSS class for first UL * @param string $indent initial indentation * @param int|null $minDepth minimum depth * @param int|null $maxDepth maximum depth @@ -557,7 +557,7 @@ protected function normalizeOptions(array $options = array()) } else { $options['ulClass'] = $this->getUlClass(); } - + if (array_key_exists('minDepth', $options)) { if (null !== $options['minDepth']) { $options['minDepth'] = (int) $options['minDepth'];