Skip to content

Commit

Permalink
Refactoring urlReplaceModule
Browse files Browse the repository at this point in the history
  • Loading branch information
boehsermoe committed Nov 20, 2018
1 parent 273a03b commit ec1cf2e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 8 additions & 4 deletions core/web/UrlManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,16 +358,20 @@ private function urlReplaceModule($url, $navItemId, Composition $composition)
throw new BadRequestHttpException("Unable to find nav_item_id '$navItemId' to generate the module link for url '$url'.");
}

$isOutgoingModulePage = $item->type == 2 && $moduleName !== $item->moduleName;

// 1. if the current page is a module and the requested url is not the same module, its an outgoing link to
// another module which should not be modificated.
// 2. If the current page (nav) context is the homepage, we have to keep the original link as it wont work because the homepage
// does not have a route prefix.
if (($item->type == 2 && $moduleName !== $item->moduleName) || $item->isHome) {
if ($isOutgoingModulePage || $item->isHome) {
return $url;
}

// if current controller context has an other module as the requested url, its an outgoing link to another module which should not be modificated.
if ($moduleName !== $item->moduleName && $moduleName !== Yii::$app->controller->module->id) {

// 1. if the current page is a module and the requested url is not the same module, its an outgoing link to
// another module and ...
// 2. if current controller context has an other module as the requested url, its an outgoing link to another module which should not be modificated.
if ($isOutgoingModulePage && $moduleName !== Yii::$app->controller->module->id) {
return $url;
}

Expand Down
4 changes: 0 additions & 4 deletions tests/data/classes/UnitMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ class Item

public $link = 'this-is-a-cms-link';

public $moduleName = null;

public $isHome = false;
}

Expand All @@ -74,8 +72,6 @@ class ItemHome

public $link = 'this-is-a-cms-link';

public $moduleName = null;

public $isHome = true;
}

Expand Down

0 comments on commit ec1cf2e

Please sign in to comment.