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

Commit

Permalink
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Page/AbstractPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public static function factory($options)
*
* @param array|Traversable $options [optional] page options. Default is
* null, which should set defaults.
* @throws Exception if invalid options are given
* @throws Exception\InvalidArgumentException if invalid options are given
*/
public function __construct($options = null)
{
Expand Down Expand Up @@ -475,6 +475,8 @@ public function getTarget()
*
* @param array|Traversable $relations [optional] an associative array of
* forward links to other pages
* @throws Exception\InvalidArgumentException if $relations is not an array
* or Traversable object
* @return AbstractPage fluent interface, returns self
*/
public function setRel($relations = null)
Expand Down Expand Up @@ -539,6 +541,8 @@ public function getRel($relation = null)
* @param array|Traversable $relations [optional] an associative array of
* reverse links to other pages
*
* @throws Exception\InvalidArgumentException if $relations it not an array
* or Traversable object
* @return AbstractPage fluent interface, returns self
*/
public function setRev($relations = null)
Expand Down Expand Up @@ -811,6 +815,7 @@ public function getVisible($recursive = false)
*
* @param AbstractContainer $parent [optional] new parent to set.
* Default is null which will set no parent.
* @throws Exception\InvalidArgumentException
* @return AbstractPage fluent interface, returns self
*/
public function setParent(AbstractContainer $parent = null)
Expand Down
5 changes: 5 additions & 0 deletions src/Page/Mvc.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Zend\Mvc\Router\RouteMatch;
use Zend\Mvc\Router\RouteStackInterface;
use Zend\Navigation\Exception;
use Zend\Mvc\ModuleRouteListener;
use Zend\View\Helper\Url as UrlHelper;

/**
Expand Down Expand Up @@ -110,6 +111,10 @@ public function isActive($recursive = false)
if ($this->routeMatch instanceof RouteMatch) {
$reqParams = $this->routeMatch->getParams();

if (isset($reqParams[ModuleRouteListener::ORIGINAL_CONTROLLER])) {
$reqParams['controller'] = $reqParams[ModuleRouteListener::ORIGINAL_CONTROLLER];
}

$myParams = $this->params;
if (null !== $this->controller) {
$myParams['controller'] = $this->controller;
Expand Down
34 changes: 34 additions & 0 deletions test/Page/MvcTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
use Zend\Mvc\Router\Http\Regex as RegexRoute;
use Zend\Mvc\Router\Http\Literal as LiteralRoute;
use Zend\Mvc\Router\Http\TreeRouteStack;
use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\MvcEvent;
use Zend\Navigation\Page;
use Zend\Navigation;
use ZendTest\Navigation\TestAsset;
Expand Down Expand Up @@ -122,6 +124,38 @@ public function testIsActiveReturnsTrueWhenMatchingRoute()
$this->assertEquals(true, $page->isActive());
}

public function testIsActiveReturnsTrueWhenMatchingRouteWhileUsingModuleRouteListener()
{
$page = new Page\Mvc(array(
'label' => 'mpinkstonwashere',
'route' => 'roflcopter',
'controller' => 'index'
));

$route = new LiteralRoute('/roflcopter');

$router = new TreeRouteStack;
$router->addRoute('roflcopter', $route);

$routeMatch = new RouteMatch(array(
ModuleRouteListener::MODULE_NAMESPACE => 'Application\Controller',
'controller' => 'index'
));
$routeMatch->setMatchedRouteName('roflcopter');

$event = new MvcEvent();
$event->setRouter($router)
->setRouteMatch($routeMatch);

$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->onRoute($event);

$page->setRouter($event->getRouter());
$page->setRouteMatch($event->getRouteMatch());

$this->assertEquals(true, $page->isActive());
}

public function testIsActiveReturnsFalseWhenMatchingRouteButNonMatchingParams()
{
$page = new Page\Mvc(array(
Expand Down

0 comments on commit b0f56ea

Please sign in to comment.