Navigation Menu

Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Merge branch 'feature/5803' into develop
Browse files Browse the repository at this point in the history
Close #5803
Fixes #2925
  • Loading branch information
weierophinney committed Mar 5, 2014
2 parents c246bca + 28f4071 commit 29ab1f2
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -34,6 +34,10 @@ version of PHP available to ensure you have the latest security fixes.

Additional updates that may affect existing applications include:

- [#5803](https://github.com/zendframework/zf2/pull/5803) adds a new flag to
`Zend\Navigation` containers' `hasPages()` method, `$onlyVisible`. If set to
`true`, only pages that are visibile based on ACLs will be considered.

- [#5759](https://github.com/zendframework/zf2/pull/5759) adds a new method to
the `FlashMessenger` view helper, `renderCurrent()`, which will render
messages registered with the `FlashMessenger` during the current request (vs.
Expand Down
12 changes: 11 additions & 1 deletion library/Zend/Navigation/AbstractContainer.php
Expand Up @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions library/Zend/View/Helper/Navigation/Menu.php
Expand Up @@ -141,10 +141,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) {
Expand Down Expand Up @@ -293,7 +293,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
Expand Down
20 changes: 18 additions & 2 deletions tests/ZendTest/Navigation/ContainerTest.php
Expand Up @@ -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);
Expand Down

0 comments on commit 29ab1f2

Please sign in to comment.