languages = $languages; $this->seo = \Yii::$container->get('artbox\core\components\SeoComponent'); parent::__construct($config); } public function init() { parent::init(); if ($this->seo->loaded) { $currentAlias = Alias::findOne($this->seo->getAliasId()); $aliases = Alias::find() ->where( [ 'route' => $currentAlias->route, ] ) ->indexBy('language_id') ->all(); /** * @var Alias[] $aliases */ foreach ($aliases as $alias) { if ($alias->id === $this->seo->getAliasId()) { $active = true; } else { $active = false; } if (( $alias->language_id === $this->languages->getDefault( )->id ) && \Yii::$app->urlManager->hideDefaultLanguagePrefix) { $url = '/' . $alias->value; } else { $url = '/' . $this->languages->getUrlById($alias->language_id) . '/' . $alias->value; } $this->links[] = [ 'active' => $active, 'url' => $url, 'title' => $this->languages->getUrlById($alias->id), ]; } } else { $languages = $this->languages->getActive(); foreach ($languages as $language) { if ($language->id === $this->languages->getCurrent()->id) { $active = true; } else { $active = false; } if (( $language->id === $this->languages->getDefault( )->id ) && \Yii::$app->urlManager->hideDefaultLanguagePrefix) { $prefix = ''; } else { $prefix = '/' . $language->url; } $url = $prefix . '/' . \Yii::$app->request->pathInfo; $this->links[] = [ 'active' => $active, 'url' => $url, 'title' => $language->url, ]; } } } public function run() { return $this->render( '_languages', [ 'links' => $this->links, ] ); } }