Verified Commit eab0949b authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #3348686 by james.williams, FeyP, kunal_sahu, larowlan, alexpott:...

Issue #3348686 by james.williams, FeyP, kunal_sahu, larowlan, alexpott: [regression] Inaccessible language switcher links are removed before alternatives can be provided

(cherry picked from commit 19b15e00)
parent d5fc1a8f
Loading
Loading
Loading
Loading
+17 −15
Original line number Diff line number Diff line
@@ -410,6 +410,11 @@ public function getLanguageSwitchLinks($type, Url $url) {
        if ($reflector->implementsInterface('\Drupal\language\LanguageSwitcherInterface')) {
          $original_languages = $this->negotiatedLanguages;
          $result = $this->negotiator->getNegotiationMethodInstance($method_id)->getLanguageSwitchLinks($this->requestStack->getCurrentRequest(), $type, $url);

          if (!empty($result)) {
            // Allow modules to provide translations for specific links.
            $this->moduleHandler->alter('language_switch_links', $result, $type, $url);

            $result = array_filter($result, function (array $link): bool {
              $url = $link['url'] ?? NULL;
              $language = $link['language'] ?? NULL;
@@ -426,9 +431,6 @@ public function getLanguageSwitchLinks($type, Url $url) {
            });
            $this->negotiatedLanguages = $original_languages;

          if (!empty($result)) {
            // Allow modules to provide translations for specific links.
            $this->moduleHandler->alter('language_switch_links', $result, $type, $url);
            $links = (object) ['links' => $result, 'method_id' => $method_id];
            break;
          }
+2 −1
Original line number Diff line number Diff line
@@ -105,5 +105,6 @@ function language_test_module_preinstall() {
 * Implements hook_language_switch_links_alter().
 */
function language_test_language_switch_links_alter(array &$links, $type, Url $url) {
  // I'll just sit here and wait to be called with the right arguments.
  // Record which languages had links passed in.
  \Drupal::state()->set('language_test.language_switch_link_ids', array_keys($links));
}
+6 −0
Original line number Diff line number Diff line
@@ -612,6 +612,12 @@ protected function assertLinkMarkup(string $path, int $status, string $marker, s
    else {
      $this->assertSession()->responseNotContains($restricted);
    }

    // Assert that all languages had a link passed to
    // hook_language_switch_links_alter() to allow alternatives to be provided.
    $languages = \Drupal::languageManager()->getNativeLanguages();
    $links_for_alter = \Drupal::state()->get('language_test.language_switch_link_ids');
    $this->assertSame(array_keys($languages), $links_for_alter);
  }

  /**