public function createUrl($params) { if (!Yii::$app->has('composition')) { return parent::createUrl($params); } $links = Yii::$app->get('links', false); $composition = Yii::$app->composition->getFull(); $originalParams = $params; $params[0] = $composition . $params[0]; $response = parent::createUrl($params); // we have not found the composition rule matching against rules, so use the original params and try again! if (strpos($response, $params[0]) !== false) { $params = $originalParams; $response = parent::createUrl($params); } else { // now we have to remove the composition informations from the links to make a valid link parsing (read module) $params[0] = str_replace($composition, '', $params[0]); } $params = (array) $params; $moduleName = \luya\helpers\Url::fromRoute($params[0], 'module'); if ($this->getContextNavItemId() && $links !== null) { $link = $links->findOneByArguments(['id' => (int) $this->getContextNavItemId()]); $this->resetContext(); return preg_replace("/{$moduleName}/", $composition . $link['url'], $response, 1); } $context = false; if ($moduleName !== false) { $moduleObject = \yii::$app->getModule($moduleName); if (method_exists($moduleObject, 'setContext') && !empty($moduleObject->context)) { if ($links !== null) { $context = true; $options = $moduleObject->getContextOptions(); $link = $links->findOneByArguments(['id' => (int) $options['navItemId']]); $response = preg_replace("/{$moduleName}/", $composition . $link['url'], $response, 1); } } } if (!$context) { // because the urlCreation of yii returns a realtive url we have to manually add the composition getFull() path. $baseUrl = yii::$app->request->baseUrl; if (empty($baseUrl)) { $response = Url::removeTrailing($composition) . $response; } else { $response = str_replace($baseUrl, Url::trailing($baseUrl) . Url::removeTrailing($composition), $response); } } return $response; }