src/Contao/View/Contao2BackendView/Filter/LanguageFilter.php
private function checkLanguage($environment, $resetToFallback)
    {
        $sessionStorage = $environment->getSessionStorage();
        $dataProvider   = $environment->getDataProvider();
        $providerName   = $environment->getDataDefinition()->getName();
        $modelId        = $this->modelIdFromInput($environment->getInputProvider());
        $languages      = $environment->getController()->getSupportedLanguages($modelId);

        if (!$languages) {
            return;
        }

        // Exit out when not a multi language provider.
        if (!($dataProvider instanceof MultiLanguageDataProviderInterface)) {
            return;
        }

        // If a new item, we MUST reset to the fallback as that is the first language that has to be stored
        // and set this language to session.
        if ((null === $modelId) && $resetToFallback) {
            $dataProvider->setCurrentLanguage($dataProvider->getFallbackLanguage(null)->getLocale());
            $session['ml_support'][$providerName] = $dataProvider->getCurrentLanguage();
            $sessionStorage->set('dc_general', $session);
            return;
        }

        $this->checkLanguageSubmit($environment, $languages);

        // Load language from Session.
        $session = (array) $sessionStorage->get('dc_general');

        // Try to get the language from session.
        $currentLanguage = ($session['ml_support'][$providerName] ?? $GLOBALS['TL_LANGUAGE']);

        if (!\array_key_exists($currentLanguage, $languages)) {
            $currentLanguage = $dataProvider->getFallbackLanguage($modelId)->getLocale();
        }

        $session['ml_support'][$providerName] = $currentLanguage;
        $sessionStorage->set('dc_general', $session);

        $dataProvider->setCurrentLanguage($currentLanguage);
    }
private function checkLanguage($environment, $resetToFallback)
    {
        $sessionStorage = $environment->getSessionStorage();
        $dataProvider   = $environment->getDataProvider();
        $providerName   = $environment->getDataDefinition()->getName();
        $modelId        = $this->modelIdFromInput($environment->getInputProvider());
        $languages      = $environment->getController()->getSupportedLanguages($modelId);

        if (!$languages) {
            return;
        }

        // Exit out when not a multi language provider.
        if (!($dataProvider instanceof MultiLanguageDataProviderInterface)) {
            return;
        }

        // If a new item, we MUST reset to the fallback as that is the first language that has to be stored
        // and set this language to session.
        if ((null === $modelId) && $resetToFallback) {
            $dataProvider->setCurrentLanguage($dataProvider->getFallbackLanguage(null)->getLocale());
            $session['ml_support'][$providerName] = $dataProvider->getCurrentLanguage();
            $sessionStorage->set('dc_general', $session);
            return;
        }

        $this->checkLanguageSubmit($environment, $languages);

        // Load language from Session.
        $session = (array) $sessionStorage->get('dc_general');

        // Try to get the language from session.
        $currentLanguage = ($session['ml_support'][$providerName] ?? $GLOBALS['TL_LANGUAGE']);

        if (!\array_key_exists($currentLanguage, $languages)) {
            $currentLanguage = $dataProvider->getFallbackLanguage($modelId)->getLocale();
        }

        $session['ml_support'][$providerName] = $currentLanguage;
        $sessionStorage->set('dc_general', $session);

        $dataProvider->setCurrentLanguage($currentLanguage);
    }
private function checkLanguage ( $ environment , $ resetToFallback ) { $ sessionStorage = $ environment -> getSessionStorage ( ) ; $ dataProvider = $ environment -> getDataProvider ( ) ; $ providerName = $ environment -> getDataDefinition ( ) -> getName ( ) ; $ modelId = $ this -> modelIdFromInput ( $ environment -> getInputProvider ( ) ) ; $ languages = $ environment -> getController ( ) -> getSupportedLanguages ( $ modelId ) ; if ( ! $ languages ) { return ; } // Exit out when not a multi language provider. if ( ! ( $ dataProvider instanceof MultiLanguageDataProviderInterface ) ) { return ; } // If a new item, we MUST reset to the fallback as that is the first language that has to be stored // and set this language to session. if ( ( null === $ modelId ) && $ resetToFallback ) { $ dataProvider -> setCurrentLanguage ( $ dataProvider -> getFallbackLanguage ( null ) -> getLocale ( ) ) ; $ session [ 'ml_support' ] [ $ providerName ] = $ dataProvider -> getCurrentLanguage ( ) ; $ sessionStorage -> set ( 'dc_general' , $ session ) ; return ; } $ this -> checkLanguageSubmit ( $ environment , $ languages ) ; // Load language from Session. $ session = ( array ) $ sessionStorage -> get ( 'dc_general' ) ; // Try to get the language from session. $ currentLanguage = ( $ session [ 'ml_support' ] [ $ providerName ] ?? $ GLOBALS [ 'TL_LANGUAGE' ] ) ; if ( ! \ array_key_exists ( $ currentLanguage , $ languages ) ) { $ currentLanguage = $ dataProvider -> getFallbackLanguage ( $ modelId ) -> getLocale ( ) ; } $ session [ 'ml_support' ] [ $ providerName ] = $ currentLanguage ; $ sessionStorage -> set ( 'dc_general' , $ session ) ; $ dataProvider -> setCurrentLanguage ( $ currentLanguage ) ; }
Check if the data provider is multi language and prepare the data provider with the selected language.

@param EnvironmentInterface $environment     The environment.
@param bool                 $resetToFallback Flag if the language must be reset to the fallback.

@return void

@SuppressWarnings(PHPMD.Superglobals)
@SuppressWarnings(PHPMD.CamelCaseVariableName)
Check if the data provider is multi language and prepare the data provider with the selected language .