diff --git a/core/lib/Drupal/Core/Language/language.api.php b/core/lib/Drupal/Core/Language/language.api.php index 1ac4b083555c219ade688e3611965ece38697444..33c1ce69f8f272b13a24dd85e5968a3db33cf935 100644 --- a/core/lib/Drupal/Core/Language/language.api.php +++ b/core/lib/Drupal/Core/Language/language.api.php @@ -162,14 +162,14 @@ * translated link text before going through the link generator, which will * just handle the path aliases. * - * @param $links + * @param array $links * Nested array of links keyed by language code. - * @param $type + * @param string $type * The language type the links will switch. - * @param $path - * The current path. + * @param \Drupal\Core\Url $url + * The URL the switch links will be relative to. */ -function hook_language_switch_links_alter(array &$links, $type, $path) { +function hook_language_switch_links_alter(array &$links, $type, \Drupal\Core\Url $url) { $language_interface = \Drupal::languageManager()->getCurrentLanguage(); if ($type == LanguageInterface::TYPE_CONTENT && isset($links[$language_interface->getId()])) { diff --git a/core/modules/language/src/ConfigurableLanguageManager.php b/core/modules/language/src/ConfigurableLanguageManager.php index 238bd830c7ee26260044f0e4513d42323870de40..614cf7737cf24d1efd5e689ccd37fd608cf00308 100644 --- a/core/modules/language/src/ConfigurableLanguageManager.php +++ b/core/modules/language/src/ConfigurableLanguageManager.php @@ -414,7 +414,7 @@ public function getLanguageSwitchLinks($type, Url $url) { if (!empty($result)) { // Allow modules to provide translations for specific links. - $this->moduleHandler->alter('language_switch_links', $result, $type, $path); + $this->moduleHandler->alter('language_switch_links', $result, $type, $url); $links = (object) array('links' => $result, 'method_id' => $method_id); break; } diff --git a/core/modules/language/tests/language_test/language_test.module b/core/modules/language/tests/language_test/language_test.module index 2ca1ff5eafac8e2c04656b4ba87bfb42e6f8612f..4803202f2610bb5611656ec28e5cccdb2e825475 100644 --- a/core/modules/language/tests/language_test/language_test.module +++ b/core/modules/language/tests/language_test/language_test.module @@ -6,6 +6,7 @@ */ use Drupal\Core\Language\LanguageInterface; +use Drupal\Core\Url; use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUI; /** @@ -99,3 +100,10 @@ function language_test_language_fallback_candidates_test_alter(array &$candidate function language_test_module_preinstall() { \Drupal::state()->set('language_test.language_count_preinstall', count(\Drupal::languageManager()->getLanguages())); } + +/** + * 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. +} diff --git a/core/modules/language/tests/src/Kernel/ConfigurableLanguageManagerTest.php b/core/modules/language/tests/src/Kernel/ConfigurableLanguageManagerTest.php new file mode 100644 index 0000000000000000000000000000000000000000..dae3a585c83776fc6d3d2c36a23ed410983d1e35 --- /dev/null +++ b/core/modules/language/tests/src/Kernel/ConfigurableLanguageManagerTest.php @@ -0,0 +1,56 @@ +installSchema('system', ['sequence']); + $this->installEntitySchema('user'); + + $this->languageNegotiator = $this->container->get('language_negotiator'); + $this->languageManager = $this->container->get('language_manager'); + } + + /** + * @covers ::getLanguageSwitchLinks + */ + public function testLanguageSwitchLinks() { + $this->languageNegotiator->setCurrentUser($this->prophesize('Drupal\Core\Session\AccountInterface')->reveal()); + $this->languageManager->getLanguageSwitchLinks(LanguageInterface::TYPE_INTERFACE, new Url('')); + } + +}