Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong URLs for language chooser #199

Open
martinlagler opened this issue Sep 29, 2021 · 1 comment
Open

Wrong URLs for language chooser #199

martinlagler opened this issue Sep 29, 2021 · 1 comment
Labels
Bug Error or unexpected behavior of already existing functionality

Comments

@martinlagler
Copy link

The URLs for the language chooser are not set correctly.

@niklasnatter
Copy link
Contributor

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;
}

@alexander-schranz alexander-schranz added this to the Stable Release milestone Sep 30, 2021
@alexander-schranz alexander-schranz added Bug Error or unexpected behavior of already existing functionality DX Only affecting the end developer and removed DX Only affecting the end developer labels Sep 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Error or unexpected behavior of already existing functionality
Projects
None yet
Development

No branches or pull requests

3 participants