Skip to content
Snippets Groups Projects
Verified Commit 36f73503 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3109600 by znerol, andypost, daffie, xjm: Convert uses of $_SESSION in language module

parent dc39dd56
No related branches found
No related tags found
40 merge requests!54479.5.x SF update,!5014Issue #3071143: Table Render Array Example Is Incorrect,!3878Removed unused condition head title for views,!38582585169-10.1.x,!3818Issue #2140179: $entity->original gets stale between updates,!3742Issue #3328429: Create item list field formatter for displaying ordered and unordered lists,!3731Claro: role=button on status report items,!3668Resolve #3347842 "Deprecate the trusted",!3651Issue #3347736: Create new SDC component for Olivero (header-search),!3546refactored dialog.pcss file,!3531Issue #3336994: StringFormatter always displays links to entity even if the user in context does not have access,!3502Issue #3335308: Confusing behavior with FormState::setFormState and FormState::setMethod,!3452Issue #3332701: Refactor Claro's tablesort-indicator stylesheet,!3451Issue #2410579: Allows setting the current language programmatically.,!3355Issue #3209129: Scrolling problems when adding a block via layout builder,!3226Issue #2987537: Custom menu link entity type should not declare "bundle" entity key,!3154Fixes #2987987 - CSRF token validation broken on routes with optional parameters.,!3147Issue #3328457: Replace most substr($a, $i) where $i is negative with str_ends_with(),!3146Issue #3328456: Replace substr($a, 0, $i) with str_starts_with(),!3133core/modules/system/css/components/hidden.module.css,!31312878513-10.1.x,!2964Issue #2865710 : Dependencies from only one instance of a widget are used in display modes,!2812Issue #3312049: [Followup] Fix Drupal.Commenting.FunctionComment.MissingReturnType returns for NULL,!2614Issue #2981326: Replace non-test usages of \Drupal::logger() with IoC injection,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2334Issue #3228209: Add hasRole() method to AccountInterface,!2062Issue #3246454: Add weekly granularity to views date sort,!1591Issue #3199697: Add JSON:API Translation experimental module,!1255Issue #3238922: Refactor (if feasible) uses of the jQuery serialize function to use vanillaJS,!1105Issue #3025039: New non translatable field on translatable content throws error,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!877Issue #2708101: Default value for link text is not saved,!844Resolve #3036010 "Updaters",!673Issue #3214208: FinishResponseSubscriber could create duplicate headers,!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493,!485Sets the autocomplete attribute for username/password input field on login form.
Pipeline #27728 failed
Pipeline: drupal

#27737

    Pipeline: drupal

    #27736

      Pipeline: drupal

      #27735

        +1
        ...@@ -4,11 +4,14 @@ ...@@ -4,11 +4,14 @@
        use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Language\LanguageInterface;
        use Drupal\Core\PathProcessor\OutboundPathProcessorInterface; use Drupal\Core\PathProcessor\OutboundPathProcessorInterface;
        use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
        use Drupal\Core\Render\BubbleableMetadata; use Drupal\Core\Render\BubbleableMetadata;
        use Drupal\Core\Url; use Drupal\Core\Url;
        use Drupal\language\LanguageNegotiationMethodBase; use Drupal\language\LanguageNegotiationMethodBase;
        use Drupal\language\LanguageSwitcherInterface; use Drupal\language\LanguageSwitcherInterface;
        use Symfony\Component\DependencyInjection\ContainerInterface;
        use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
        use Symfony\Component\HttpFoundation\RequestStack;
        /** /**
        * Identify language from a request/session parameter. * Identify language from a request/session parameter.
        ...@@ -21,7 +24,7 @@ ...@@ -21,7 +24,7 @@
        * config_route_name = "language.negotiation_session" * config_route_name = "language.negotiation_session"
        * ) * )
        */ */
        class LanguageNegotiationSession extends LanguageNegotiationMethodBase implements OutboundPathProcessorInterface, LanguageSwitcherInterface { class LanguageNegotiationSession extends LanguageNegotiationMethodBase implements OutboundPathProcessorInterface, LanguageSwitcherInterface, ContainerFactoryPluginInterface {
        /** /**
        * Flag used to determine whether query rewriting is active. * Flag used to determine whether query rewriting is active.
        ...@@ -44,22 +47,53 @@ class LanguageNegotiationSession extends LanguageNegotiationMethodBase implement ...@@ -44,22 +47,53 @@ class LanguageNegotiationSession extends LanguageNegotiationMethodBase implement
        */ */
        protected $queryValue; protected $queryValue;
        /**
        * The request stack.
        *
        * @var \Symfony\Component\HttpFoundation\RequestStack
        */
        protected $requestStack;
        /** /**
        * The language negotiation method id. * The language negotiation method id.
        */ */
        const METHOD_ID = 'language-session'; const METHOD_ID = 'language-session';
        /**
        * Constructs a LanguageNegotiationSession object.
        *
        * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
        * The request stack.
        */
        public function __construct(RequestStack $request_stack) {
        $this->requestStack = $request_stack;
        }
        /**
        * {@inheritdoc}
        */
        public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
        return new static(
        $container->get('request_stack')
        );
        }
        /** /**
        * {@inheritdoc} * {@inheritdoc}
        */ */
        public function getLangcode(Request $request = NULL) { public function getLangcode(Request $request = NULL) {
        $config = $this->config->get('language.negotiation')->get('session'); $config = $this->config->get('language.negotiation')->get('session');
        $param = $config['parameter']; if (($param = $config['parameter']) && $request) {
        $langcode = $request && $request->query->get($param) ? $request->query->get($param) : NULL; if ($request->query->has($param)) {
        if (!$langcode && isset($_SESSION[$param])) { return $request->query->get($param);
        $langcode = $_SESSION[$param]; }
        // @todo Remove hasSession() from condition in
        // https://www.drupal.org/node/2484991
        if ($request->hasSession() && $request->getSession()->has($param)) {
        return $request->getSession()->get($param);
        }
        } }
        return $langcode; return NULL;
        } }
        /** /**
        ...@@ -73,7 +107,7 @@ public function persist(LanguageInterface $language) { ...@@ -73,7 +107,7 @@ public function persist(LanguageInterface $language) {
        $languages = $this->languageManager->getLanguages(); $languages = $this->languageManager->getLanguages();
        if ($this->currentUser->isAuthenticated() && isset($languages[$langcode])) { if ($this->currentUser->isAuthenticated() && isset($languages[$langcode])) {
        $config = $this->config->get('language.negotiation')->get('session'); $config = $this->config->get('language.negotiation')->get('session');
        $_SESSION[$config['parameter']] = $langcode; $this->requestStack->getCurrentRequest()->getSession()->set($config['parameter'], $langcode);
        } }
        } }
        } }
        ...@@ -129,7 +163,7 @@ public function getLanguageSwitchLinks(Request $request, $type, Url $url) { ...@@ -129,7 +163,7 @@ public function getLanguageSwitchLinks(Request $request, $type, Url $url) {
        parse_str($request->getQueryString() ?? '', $query); parse_str($request->getQueryString() ?? '', $query);
        $config = $this->config->get('language.negotiation')->get('session'); $config = $this->config->get('language.negotiation')->get('session');
        $param = $config['parameter']; $param = $config['parameter'];
        $language_query = $_SESSION[$param] ?? $this->languageManager->getCurrentLanguage($type)->getId(); $language_query = $request->getSession()->has($param) ? $request->getSession()->get($param) : $this->languageManager->getCurrentLanguage($type)->getId();
        foreach ($this->languageManager->getNativeLanguages() as $language) { foreach ($this->languageManager->getNativeLanguages() as $language) {
        $langcode = $language->getId(); $langcode = $language->getId();
        ......
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Finish editing this message first!
        Please register or to comment