From cbf8710b9c1fc60d9de55ae1287e92bdaca1dc5a Mon Sep 17 00:00:00 2001 From: boehsermoe Date: Fri, 23 Nov 2018 20:56:34 +0100 Subject: [PATCH] Url module controller context fix (#1877) * Translation helper controler * PHPdoc * Correct parameter order for help * Bugfix with language switcher #1876 * Unit test fix * Refactoring urlReplaceModule * Changelog * Typo --- core/CHANGELOG.md | 8 +++++++- core/web/UrlManager.php | 12 ++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index 721fe4b57..e50a3460d 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to this project will be documented in this file. This project make usage of the [Yii Versioning Strategy](https://github.com/yiisoft/yii2/blob/master/docs/internals/versions.md). In order to read more about upgrading and BC breaks have a look at the [UPGRADE Document](UPGRADE.md). +## 1.0.15 (in progress) + +### Fixed + ++ [#1876](https://github.com/luyadev/luya/issues/1876) Fixed the url generation without module context when using language switcher. + ## 1.0.14 (17. November 2018) + [#1872](https://github.com/luyadev/luya/issues/1872) Added new schemas for Json-Ld. Fixed Event Json-Ld, and TypeHinting. @@ -18,7 +24,7 @@ All notable changes to this project will be documented in this file. This projec ## 1.0.12 (8. October 2018) -+ [#1856](https://github.com/luyadev/luya/issues/1856) If application console method is runing, the cli determination should be forced. ++ [#1856](https://github.com/luyadev/luya/issues/1856) If application console method is running, the cli determination should be forced. + [#1853](https://github.com/luyadev/luya/issues/1853) Add option to lazy load mocked arguments. + [#1852](https://github.com/luyadev/luya/pull/1852) Updated Svg widget to enable usage of symbols (svg sprite) via svg > use implementation + [#1851](https://github.com/luyadev/luya/issues/1851) Add string helper method highlightWord() to highlight a given word withing a string. diff --git a/core/web/UrlManager.php b/core/web/UrlManager.php index 57cc3413d..b3bc64dc0 100644 --- a/core/web/UrlManager.php +++ b/core/web/UrlManager.php @@ -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 !== 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; }