Leuchtfeuer/locate

Target language equals current language. No redirect. But it's not the same page

niederberger-qw opened this issue · 4 comments

We have Different Sites with different languages. But the languages are all sys_language_uid 0, because it's the default language for the site.

For example:
grafik
grafik
Every language is sys_language_uid 0

To reproduce this try to redirect from pages with the same sys_language_uid.

I have different verdicts:
redirectToPageFrance = Leuchtfeuer\Locate\Verdict\Redirect
redirectToPageFrance {
sys_language = 0
page = 12
}

redirectToPageBelgiqueFr = Leuchtfeuer\Locate\Verdict\Redirect
redirectToPageBelgiqueFr {
sys_language = 0
page = 11
}

redirectToPageDeutschland = Leuchtfeuer\Locate\Verdict\Redirect
redirectToPageDeutschland {
sys_language = 0
page = 1
}

The page is not redirected.

I did comment the line out:
grafik

But the redirect is not working, because the wrong site is called for the getRouter() function.
grafik

In the GLOBALS['TYPO3_REQUEST']->getAttribute('site') we get the current site. I don't know i it's possible to generate the right uri with the wrong $site variable.

grafik
the parameters are right, but the uri shows to the wrong site.

I don't know how to do a pull request... But i fixed the error, after i did the following:

In locate/Classes/Verdict/Redirect.php

Line 184:

if ($pageId === $GLOBALS["TSFE"]->page["uid"]){
            if (($page['sys_language_uid'] === $targetLanguageId && $targetLanguageId !== 0) || $this->requestedLanguageUid === $targetLanguageId) {
                $this->logger->info('Target language equals current language. No redirect.');

                return null;
            }
        }

Line 204:

 $siteFinder = new \TYPO3\CMS\Core\Site\SiteFinder();

        /** @var Site $site */
        $site = $siteFinder->getSiteByPageId($pageId);

Okay... it only works if sessionHandling = 0

If it is 1, then the function isSessionInCurrentLanguage() is the problem.

Is that a bug or a feature? I mean... did i configure something wrong?!

Thanks for your feedback. It is indeed a desired behaviour. The redirect should only take place if the sys_language_uid is different then the uid stored in the session. In your system every sys_language_uid is 0 so there is no reason for the extension to make the redirect to a different language because it is already on the sys_language_uid 0. What you need is only a redirect to a certain page if the user has a specific browser language but not change the system language itself.
You can write a custom verdict to handle that behaviour by yourself, see the documentation for that part: https://docs.typo3.org/p/leuchtfeuer/locate/main/en-us/Developing/Index.html#add-a-verdict
In your case you can copy most of the Redirect verdict and adapt the parts of the code you need to.