Open martinlagler opened 2 years ago
Thanks for reporting! The problem here is that the localizations
twig variable is not set correctly at the moment. For pages, this is done in the ParameterResolver
:
https://github.com/sulu/sulu/blob/206afbf7e510daa688dfd7735c69551a988f9be3/src/Sulu/Bundle/WebsiteBundle/Resolver/ParameterResolver.php#L119-L124
In the SuluArticleBundle
, this is done in the WebsiteArticleUrlsSubscriber
:
https://github.com/sulu/SuluArticleBundle/blob/2d2ce3e0c54b63c6752b1ba1c016f77ba2ce66e5/Document/Serializer/WebsiteArticleUrlsSubscriber.php#L106-L110
As a workaround, we have set the correct data to the localization
variable in a custom controller inside of the project:
protected function getAttributes($attributes, StructureInterface $structure = null, $preview = false)
{
$attributes = parent::getAttributes($attributes, $structure, $preview);
$webspace = $this->get('sulu_core.webspace.request_analyzer')->getWebspace();
$attributes['urls'] = [];
$attributes['localizations'] = [];
foreach ($webspace->getAllLocalizations() as $localization) {
$locale = $localization->getLocale();
if (!$structure) {
continue;
}
$route = $this->routeRepository->findByEntity(ProductDimensionContent::getContentClass(), $structure->getUuid(), $locale);
$path = $route ? $route->getPath() : '/';
$attributes['urls'][$locale] = $path;
$attributes['localizations'][$locale] = [
'locale' => $locale,
'url' => $this->webspaceManager->findUrlByResourceLocator($path, null, $locale),
];
}
return $attributes;
}
The URLs for the language chooser are not set correctly.