Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Hide sub menus if all pages in the sub menu is hidden. #5803

Closed
wants to merge 2 commits into from

3 participants

Rickard Matthew Weier O'Phinney Abdul Malik Ikhsan
Rickard

Based on ysors pull request #2925 now with tests.

library/Zend/Navigation/AbstractContainer.php
((9 lines not shown))
{
- return count($this->index) > 0;
+ if ($onlyVisible) {
+ foreach ($this->pages as $page) {
+ if ($page->isVisible()) {
+ return true;
+ }
+ }
+ // no visible pages found
+ return false;
+ } else {
+ return count($this->index) > 0;
+ }

no need else, just return count($this->index) > 0; directly after closing bracket because already return early.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Rickard

That should fix it

Matthew Weier O'Phinney weierophinney added this to the 2.3.0 milestone
Matthew Weier O'Phinney

Scheduling for 2.3 as this is technically new functionality.

Matthew Weier O'Phinney weierophinney self-assigned this
Matthew Weier O'Phinney

Merged to develop for release with 2.3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 4, 2014
  1. Rickard
Commits on Feb 9, 2014
  1. Rickard
This page is out of date. Refresh to see the latest.
12 library/Zend/Navigation/AbstractContainer.php
View
@@ -258,10 +258,20 @@ public function hasPage(Page\AbstractPage $page, $recursive = false)
/**
* Returns true if container contains any pages
*
+ * @param bool $onlyVisible whether to check only visible pages
* @return bool whether container has any pages
*/
- public function hasPages()
+ public function hasPages($onlyVisible = false)
{
+ if ($onlyVisible) {
+ foreach ($this->pages as $page) {
+ if ($page->isVisible()) {
+ return true;
+ }
+ }
+ // no visible pages found
+ return false;
+ }
return count($this->index) > 0;
}
6 library/Zend/View/Helper/Navigation/Menu.php
View
@@ -132,10 +132,10 @@ protected function renderDeepestMenu(
// special case if active page is one below minDepth
if ($active['depth'] < $minDepth) {
- if (!$active['page']->hasPages()) {
+ if (!$active['page']->hasPages(!$this->renderInvisible)) {
return '';
}
- } elseif (!$active['page']->hasPages()) {
+ } elseif (!$active['page']->hasPages(!$this->renderInvisible)) {
// found pages has no children; render siblings
$active['page'] = $active['page']->getParent();
} elseif (is_int($maxDepth) && $active['depth'] +1 > $maxDepth) {
@@ -280,7 +280,7 @@ protected function renderNormalMenu(
$accept = true;
} elseif ($foundPage->getParent()->hasPage($page)) {
// page is a sibling of the active page...
- if (!$foundPage->hasPages() ||
+ if (!$foundPage->hasPages(!$this->renderInvisible) ||
is_int($maxDepth) && $foundDepth + 1 > $maxDepth) {
// accept if active page has no children, or the
// children are too deep to be rendered
20 tests/ZendTest/Navigation/ContainerTest.php
View
@@ -682,19 +682,35 @@ public function testHasPages()
{
$nav1 = new Navigation\Navigation();
$nav2 = new Navigation\Navigation();
+ $nav3 = new Navigation\Navigation();
+ $nav4 = new Navigation\Navigation();
$nav2->addPage(array(
'label' => 'Page 1',
'uri' => '#'
));
+ $nav3->addPage(array(
+ 'label' => 'Page 1',
+ 'uri' => '#',
+ 'visible' => true
+ ));
+ $nav4->addPage(array(
+ 'label' => 'Page 1',
+ 'uri' => '#',
+ 'visible' => false
+ ));
$expected = array(
'empty' => false,
- 'notempty' => true
+ 'notempty' => true,
+ 'visible' => true,
+ 'notvisible' => false
);
$actual = array(
'empty' => $nav1->hasPages(),
- 'notempty' => $nav2->hasPages()
+ 'notempty' => $nav2->hasPages(),
+ 'visible' => $nav3->hasPages(false),
+ 'notvisible' => $nav4->hasPages(true)
);
$this->assertEquals($expected, $actual);
Something went wrong with that request. Please try again.