'Change language parameters in site configuration for some pages in a site

Is there a possibility in TYPO3 10 LTS to change the option fallbackType in the site configuration for a single page?

Background:

I use for the site the option fallbackType fallback. But for a few page I need fallbackType strict. Up to TYPO3 8 this could be achieved with a simple extension template and different config configurations. Is there a way in TYPO3 10?



Solution 1:[1]

As far as i know there is no possibility to configurate TYPO3 to behave in this way. The only way to override the language configuration for a single page is a custom middleware.

You can find a working example here: https://github.com/qbus-agentur/typo3-dynamic-language-mode.

I changed the main function:

    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
    $lang = $this->getCurrentSiteLanguage($request);
    $pageArguments = $this->getPageArguments($request);

    if ($lang === null || $pageArguments === null) {
        return $handler->handle($request);
    }

    // get current page ID
    $currentRouting = $request->getAttribute('routing');
    $currentPage = $currentRouting->getPageId();

    $site = $request->getAttribute('site');
    $default = $site->getLanguages()[0];
    if ($lang->getLanguageId() !== $default->getLanguageId()) {
        // Check if page is in $pagesWhereToChange and apply a dynamic language configuration in that case

        if (in_array($currentPage, $this->pagesWhereToChange) > 0) {
            \Closure::bind(function() use ($lang, $newId) {
                $lang->fallbackType = 'free';
                $lang->fallbackLanguageIds = [];
            }, null, SiteLanguage::class)();
        }
    }

    return $handler->handle($request);
}

Where $this->pagesWhereToChange is an array of pages:

/**
 * pagesWhereToChange
 *
 * @var array
 */
protected $pagesWhereToChange = [30,41];

It's not possible to configure the array with typoscript because TSFE is not rendered yet.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 lisardo