diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index 2f16516..49dca17 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -790,8 +790,8 @@ public function getTranslationFromContext(EntityInterface $entity, $langcode = N // Retrieve language fallback candidates to perform the entity language // negotiation. $context['data'] = $entity; - $context += array('operation' => 'entity_view'); - $candidates = $this->languageManager->getFallbackCandidates($langcode, $context); + $context += array('operation' => 'entity_view', 'langcode' => $langcode); + $candidates = $this->languageManager->getFallbackCandidates($context); // Ensure the default language has the proper language code. $default_language = $entity->getUntranslated()->language(); diff --git a/core/lib/Drupal/Core/Language/LanguageManager.php b/core/lib/Drupal/Core/Language/LanguageManager.php index 0072f0c..88e2363 100644 --- a/core/lib/Drupal/Core/Language/LanguageManager.php +++ b/core/lib/Drupal/Core/Language/LanguageManager.php @@ -194,7 +194,7 @@ public function isLanguageLocked($langcode) { /** * {@inheritdoc} */ - public function getFallbackCandidates($langcode = NULL, array $context = array()) { + public function getFallbackCandidates(array $context = array()) { return array(LanguageInterface::LANGCODE_DEFAULT); } diff --git a/core/lib/Drupal/Core/Language/LanguageManagerInterface.php b/core/lib/Drupal/Core/Language/LanguageManagerInterface.php index b3f0272..1a6732c 100644 --- a/core/lib/Drupal/Core/Language/LanguageManagerInterface.php +++ b/core/lib/Drupal/Core/Language/LanguageManagerInterface.php @@ -132,8 +132,6 @@ public function isLanguageLocked($langcode); /** * Returns the language fallback candidates for a given context. * - * @param string $langcode - * (optional) The language of the current context. Defaults to NULL. * @param array $context * (optional) An associative array of data that can be useful to determine * the fallback sequence. The following keys are used in core: @@ -147,7 +145,7 @@ public function isLanguageLocked($langcode); * An array of language codes sorted by priority: first values should be * tried first. */ - public function getFallbackCandidates($langcode = NULL, array $context = array()); + public function getFallbackCandidates(array $context = array()); /** * Returns the language switch links for the given language type. diff --git a/core/modules/field/src/Plugin/views/field/Field.php b/core/modules/field/src/Plugin/views/field/Field.php index 4705437..20e2c58 100644 --- a/core/modules/field/src/Plugin/views/field/Field.php +++ b/core/modules/field/src/Plugin/views/field/Field.php @@ -305,7 +305,7 @@ public function query($use_groupby = FALSE) { $this->view->display_handler->options['field_langcode'] ); $placeholder = $this->placeholder(); - $langcode_fallback_candidates = $this->languageManager->getFallbackCandidates($langcode, array('operation' => 'views_query', 'data' => $this)); + $langcode_fallback_candidates = $this->languageManager->getFallbackCandidates(array('langcode' => $langcode, 'operation' => 'views_query', 'data' => $this)); $this->query->addWhereExpression(0, "$column IN($placeholder) OR $column IS NULL", array($placeholder => $langcode_fallback_candidates)); } } diff --git a/core/modules/language/src/ConfigurableLanguageManager.php b/core/modules/language/src/ConfigurableLanguageManager.php index 1b72dc8..5415711 100644 --- a/core/modules/language/src/ConfigurableLanguageManager.php +++ b/core/modules/language/src/ConfigurableLanguageManager.php @@ -326,7 +326,7 @@ public function updateLockedLanguageWeights() { /** * {@inheritdoc} */ - public function getFallbackCandidates($langcode = NULL, array $context = array()) { + public function getFallbackCandidates(array $context = array()) { if ($this->isMultilingual()) { $candidates = array(); if (empty($context['operation']) || strpos($context['operation'], 'locale') !== 0) { @@ -339,9 +339,10 @@ public function getFallbackCandidates($langcode = NULL, array $context = array() $candidates[] = BaseLanguageInterface::LANGCODE_NOT_SPECIFIED; $candidates = array_combine($candidates, $candidates); - // The first candidate should always be the desired language if specified. - if (!empty($langcode)) { - $candidates = array($langcode => $langcode) + $candidates; + // The first candidate should always be the desired language if + // specified. + if (!empty($context['langcode'])) { + $candidates = array($context['langcode'] => $context['langcode']) + $candidates; } } @@ -355,7 +356,7 @@ public function getFallbackCandidates($langcode = NULL, array $context = array() $this->moduleHandler->alter($types, $candidates, $context); } else { - $candidates = parent::getFallbackCandidates($langcode, $context); + $candidates = parent::getFallbackCandidates($context); } return $candidates; diff --git a/core/modules/language/src/Tests/LanguageFallbackTest.php b/core/modules/language/src/Tests/LanguageFallbackTest.php index 3b15601..b3d3672 100644 --- a/core/modules/language/src/Tests/LanguageFallbackTest.php +++ b/core/modules/language/src/Tests/LanguageFallbackTest.php @@ -56,7 +56,7 @@ public function testCandidates() { $this->state->set('language_test.fallback_operation_alter.candidates', TRUE); $expected[] = LanguageInterface::LANGCODE_NOT_SPECIFIED; $expected[] = LanguageInterface::LANGCODE_NOT_APPLICABLE; - $candidates = $this->languageManager->getFallbackCandidates(NULL, array('operation' => 'test')); + $candidates = $this->languageManager->getFallbackCandidates(array('operation' => 'test')); $this->assertEqual(array_values($candidates), $expected, 'Language fallback candidates are alterable for specific operations.'); // Check that when the site is monolingual no language fallback is applied. diff --git a/core/modules/locale/src/LocaleLookup.php b/core/modules/locale/src/LocaleLookup.php index 960495e..74c0358 100644 --- a/core/modules/locale/src/LocaleLookup.php +++ b/core/modules/locale/src/LocaleLookup.php @@ -127,7 +127,7 @@ protected function resolveCacheMiss($offset) { // If there is no translation available for the current language then use // language fallback to try other translations. if ($value === TRUE) { - $fallbacks = $this->languageManager->getFallbackCandidates($this->langcode, array('operation' => 'locale_lookup', 'data' => $offset)); + $fallbacks = $this->languageManager->getFallbackCandidates(array('langcode' => $this->langcode, 'operation' => 'locale_lookup', 'data' => $offset)); if (!empty($fallbacks)) { foreach ($fallbacks as $langcode) { $translation = $this->stringStorage->findTranslation(array( diff --git a/core/modules/locale/src/Tests/LocaleLocaleLookupTest.php b/core/modules/locale/src/Tests/LocaleLocaleLookupTest.php index a3a6283..4314bc5 100644 --- a/core/modules/locale/src/Tests/LocaleLocaleLookupTest.php +++ b/core/modules/locale/src/Tests/LocaleLocaleLookupTest.php @@ -57,9 +57,11 @@ public function testCircularDependency() { */ public function testLanguageFallbackDefaults() { $this->drupalGet(''); - // State of fallback languages persisted by - // locale_test_language_fallback_candidates_locale_lookup_alter(). + // Ensure state of fallback languages persisted by + // locale_test_language_fallback_candidates_locale_lookup_alter() is empty. $this->assertEqual(\Drupal::state()->get('locale.test_language_fallback_candidates_locale_lookup_alter_candidates'), array()); + // Make sure there is enough information provided for alters. + $this->assertEqual(\Drupal::state()->get('locale.test_language_fallback_candidates_locale_lookup_alter_context'), array('langcode' => 'fr', 'operation' => 'locale_lookup')); } } diff --git a/core/modules/locale/tests/modules/locale_test/locale_test.module b/core/modules/locale/tests/modules/locale_test/locale_test.module index e4cd678..f06a24a 100644 --- a/core/modules/locale/tests/modules/locale_test/locale_test.module +++ b/core/modules/locale/tests/modules/locale_test/locale_test.module @@ -135,4 +135,5 @@ function locale_test_locale_translation_projects_alter(&$projects) { */ function locale_test_language_fallback_candidates_locale_lookup_alter(array &$candidates, array $context) { \Drupal::state()->set('locale.test_language_fallback_candidates_locale_lookup_alter_candidates', $candidates); + \Drupal::state()->set('locale.test_language_fallback_candidates_locale_lookup_alter_context', $context); } diff --git a/core/modules/locale/tests/src/LocaleLookupTest.php b/core/modules/locale/tests/src/LocaleLookupTest.php index 1295d7b..1e0b5a9 100644 --- a/core/modules/locale/tests/src/LocaleLookupTest.php +++ b/core/modules/locale/tests/src/LocaleLookupTest.php @@ -158,8 +158,8 @@ public function testResolveCacheMissWithFallback($langcode, $string, $context, $ $this->languageManager->expects($this->any()) ->method('getFallbackCandidates') - ->will($this->returnCallback(function ($langcode) { - switch ($langcode) { + ->will($this->returnCallback(function (array $context = array()) { + switch ($context['langcode']) { case 'pl': return array('cs', 'en'); diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php index 5cfc5d0..2fc53c9 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php @@ -928,10 +928,10 @@ public function testGetTranslationFromContext() { $this->languageManager->expects($this->exactly(2)) ->method('getFallbackCandidates') - ->will($this->returnCallback(function ($langcode = NULL, array $context = array()) { + ->will($this->returnCallback(function (array $context = array()) { $candidates = array(); - if ($langcode) { - $candidates[$langcode] = $langcode; + if (!empty($context['langcode'])) { + $candidates[$context['langcode']] = $context['langcode']; } return $candidates; }));