summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2017-02-23 11:16:52 (GMT)
committerNathaniel Catchpole2017-02-23 11:16:52 (GMT)
commit801f6ca130b5776cb032f6dbd5b4aad69b39e079 (patch)
tree0150d05a081bf07b8aa44a4364a87e0b067293aa
parentfafa49b91302983af484c85457a30e8822293456 (diff)
Issue #2585821 by blazey, marvin_B8, sdstyles, benelori, GoZ, DuaelFr: ConfigurableLanguageManager language_switch_links alter use undefined path variable
-rw-r--r--core/lib/Drupal/Core/Language/language.api.php10
-rw-r--r--core/modules/language/src/ConfigurableLanguageManager.php2
-rw-r--r--core/modules/language/tests/language_test/language_test.module8
-rw-r--r--core/modules/language/tests/src/Kernel/ConfigurableLanguageManagerTest.php56
4 files changed, 70 insertions, 6 deletions
diff --git a/core/lib/Drupal/Core/Language/language.api.php b/core/lib/Drupal/Core/Language/language.api.php
index 1ac4b08..33c1ce6 100644
--- a/core/lib/Drupal/Core/Language/language.api.php
+++ b/core/lib/Drupal/Core/Language/language.api.php
@@ -162,14 +162,14 @@ use Drupal\Core\Language\LanguageInterface;
* 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 238bd83..614cf77 100644
--- a/core/modules/language/src/ConfigurableLanguageManager.php
+++ b/core/modules/language/src/ConfigurableLanguageManager.php
@@ -414,7 +414,7 @@ class ConfigurableLanguageManager extends LanguageManager implements Configurabl
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 2ca1ff5..4803202 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 0000000..dae3a58
--- /dev/null
+++ b/core/modules/language/tests/src/Kernel/ConfigurableLanguageManagerTest.php
@@ -0,0 +1,56 @@
+<?php
+
+namespace Drupal\Tests\language\Kernel;
+
+use Drupal\Core\Language\LanguageInterface;
+use Drupal\Core\Url;
+
+/**
+ * Tests the ConfigurableLanguage entity.
+ *
+ * @group language
+ * @coversDefaultClass \Drupal\language\ConfigurableLanguageManager
+ */
+class ConfigurableLanguageManagerTest extends LanguageTestBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ public static $modules = array('user');
+
+ /**
+ * The language negotiator.
+ *
+ * @var \Drupal\language\LanguageNegotiatorInterface
+ */
+ protected $languageNegotiator;
+
+ /**
+ * The language manager.
+ *
+ * @var \Drupal\language\ConfigurableLanguageManagerInterface
+ */
+ protected $languageManager;
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function setUp() {
+ parent::setUp();
+
+ $this->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('<current>'));
+ }
+
+}