Skip to content
Snippets Groups Projects
Commit 801f6ca1 authored by catch's avatar catch
Browse files

Issue #2585821 by blazey, marvin_B8, sdstyles, benelori, GoZ, DuaelFr:...

Issue #2585821 by blazey, marvin_B8, sdstyles, benelori, GoZ, DuaelFr: ConfigurableLanguageManager language_switch_links alter use undefined path variable
parent fafa49b9
No related branches found
No related tags found
No related merge requests found
......@@ -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()])) {
......
......@@ -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;
}
......
......@@ -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.
}
<?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>'));
}
}
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