diff --git a/core/includes/language.inc b/core/includes/language.inc index af20cc9..85dce27 100644 --- a/core/includes/language.inc +++ b/core/includes/language.inc @@ -171,7 +171,6 @@ function language_types_set(array $configurable_language_types) { // \Drupal\Core\Extension\ModuleHandler::uninstall() could invalidate the // cached information. drupal_static_reset('language_types_info'); - drupal_static_reset('language_negotiation_info'); $language_types = array(); $negotiation_info = language_negotiation_info(); @@ -220,10 +219,6 @@ function language_types_set(array $configurable_language_types) { $config = \Drupal::config('system.language.types'); $config->set('configurable', array_keys(array_filter($language_types)))->save(); $config->set('all', array_keys($language_types))->save(); - - // Ensure that subsequent calls of language_types_get_configurable() return - // the updated language type information. - drupal_static_reset('language_types_get_configurable'); } /** @@ -290,7 +285,7 @@ function language_negotiation_purge() { // invocation of \Drupal\Core\Extension\ModuleHandler::install() or // \Drupal\Core\Extension\ModuleHandler::uninstall() could invalidate the // cached information. - drupal_static_reset('language_negotiation_info'); + Drupal::service('plugin.manager.language_negotiation_method')->clearCachedDefinitions(); drupal_static_reset('language_types_info'); $negotiation_info = language_negotiation_info(); @@ -330,7 +325,7 @@ function language_negotiation_set($type, $method_weights) { $method = $negotiation_info[$method_id]; // If the language negotiation method does not express any preference // about types, make it available for any configurable type. - $types = array_flip(isset($method['types']) ? $method['types'] : $default_types); + $types = array_flip(!empty($method['types']) ? $method['types'] : $default_types); // Check whether the method is defined and has the right type. if (isset($types[$type])) { $method_data = array(); diff --git a/core/lib/Drupal/Core/Language/LanguageManager.php b/core/lib/Drupal/Core/Language/LanguageManager.php index 125b03d..5e79465 100644 --- a/core/lib/Drupal/Core/Language/LanguageManager.php +++ b/core/lib/Drupal/Core/Language/LanguageManager.php @@ -321,13 +321,10 @@ function getLanguageNegotiationSwitchLinks($type, $path) { $negotiation = variable_get("language_negotiation_$type", array()); foreach ($negotiation as $method_id => $method) { - if (isset($method['callbacks']['language_switch'])) { - if (isset($method['file'])) { - require_once DRUPAL_ROOT . '/' . $method['file']; - } - - $callback = $method['callbacks']['language_switch']; - $result = $callback($type, $path); + $definition = $this->negotiatorManager->getDefinition($method_id); + if (method_exists($definition['class'], 'languageSwitchLinks')) { + $instance = $this->negotiatorManager->createInstance($method_id, $this->config); + $result = $instance->languageSwitchLinks($type, $path); if (!empty($result)) { // Allow modules to provide translations for specific links. diff --git a/core/lib/Drupal/Core/Language/Plugin/LanguageNegotiation/LanguageNegotiationInterface.php b/core/lib/Drupal/Core/Language/Plugin/LanguageNegotiation/LanguageNegotiationInterface.php new file mode 100644 index 0000000..956ed94 --- /dev/null +++ b/core/lib/Drupal/Core/Language/Plugin/LanguageNegotiation/LanguageNegotiationInterface.php @@ -0,0 +1,38 @@ +languageManager->getLanguage(); + } + +} diff --git a/core/lib/Drupal/Core/Language/Plugin/LanguageNegotiation/LanguageNegotiationSession.php b/core/lib/Drupal/Core/Language/Plugin/LanguageNegotiation/LanguageNegotiationSession.php index 759d5d4..8072069 100644 --- a/core/lib/Drupal/Core/Language/Plugin/LanguageNegotiation/LanguageNegotiationSession.php +++ b/core/lib/Drupal/Core/Language/Plugin/LanguageNegotiation/LanguageNegotiationSession.php @@ -53,4 +53,35 @@ public function negotiateLanguage(array $languages, Request $request = NULL) { return FALSE; } + /** + * Return the session language switcher block. + */ + function languageSwitchLinks($type, $path) { + $param = \Drupal::config('language.negotiation')->get('session.parameter'); + $language_query = isset($_SESSION[$param]) ? $_SESSION[$param] : language($type)->id; + + $languages = language_list(); + $links = array(); + + $query = $_GET; + + foreach ($languages as $language) { + $langcode = $language->id; + $links[$langcode] = array( + 'href' => $path, + 'title' => $language->name, + 'attributes' => array('class' => array('language-link')), + 'query' => $query, + ); + if ($language_query != $langcode) { + $links[$langcode]['query'][$param] = $langcode; + } + else { + $links[$langcode]['attributes']['class'][] = ' session-active'; + } + } + + return $links; + } + } diff --git a/core/lib/Drupal/Core/Language/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php b/core/lib/Drupal/Core/Language/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php index 756d602..00e0f3c 100644 --- a/core/lib/Drupal/Core/Language/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php +++ b/core/lib/Drupal/Core/Language/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php @@ -15,6 +15,7 @@ * * @Plugin( * id = Drupal\Core\Language\Plugin\LanguageNegotiation\LanguageNegotiationUrl::METHOD_ID, + * types = {Drupal\Core\Language\Language::TYPE_URL, Drupal\Core\Language\Language::TYPE_CONTENT, Drupal\Core\Language\Language::TYPE_URL}, * weight = -8, * name = @Translation("URL"), * description = @Translation("Language from the URL (Path prefix or domain)."), @@ -95,4 +96,25 @@ public function negotiateLanguage(array $languages, Request $request = NULL) { return $langcode; } + /** + * Return links for the URL language switcher block. + * + * Translation links may be provided by other modules. + */ + function languageSwitchLinks($type, $path) { + $languages = language_list(); + $links = array(); + + foreach ($languages as $language) { + $links[$language->id] = array( + 'href' => $path, + 'title' => $language->name, + 'language' => $language, + 'attributes' => array('class' => array('language-link')), + ); + } + + return $links; + } + } diff --git a/core/lib/Drupal/Core/Language/Plugin/LanguageNegotiation/LanguageNegotiationUrlFallback.php b/core/lib/Drupal/Core/Language/Plugin/LanguageNegotiation/LanguageNegotiationUrlFallback.php index bd47eaa..7a5d67f 100644 --- a/core/lib/Drupal/Core/Language/Plugin/LanguageNegotiation/LanguageNegotiationUrlFallback.php +++ b/core/lib/Drupal/Core/Language/Plugin/LanguageNegotiation/LanguageNegotiationUrlFallback.php @@ -37,7 +37,7 @@ * types = {Drupal\Core\Language\Language::TYPE_URL}, * weight = 8, * name = @Translation("URL fallback"), - * description = @Translation("Use an already detected language for URLs if none is found..") + * description = @Translation("Use an already detected language for URLs if none is found.") * ) */ class LanguageNegotiationUrlFallback extends LanguageNegotiationMethodBase { diff --git a/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationUITest.php b/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationUITest.php index 21c8465..fe70f16 100644 --- a/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationUITest.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationUITest.php @@ -36,7 +36,7 @@ function testTranslationUI() { $this->assertBasicTranslation(); $this->doTestTranslationOverview(); - $this->assertOutdatedStatus(); + $this->doOutdatedStatus(); $this->assertPublishedStatus(); $this->assertAuthoringInfo(); $this->assertTranslationDeletion(); @@ -117,7 +117,7 @@ protected function doTestTranslationOverview() { /** * Tests up-to-date status tracking. */ - protected function assertOutdatedStatus() { + protected function doOutdatedStatus() { $entity = entity_load($this->entityType, $this->entityId, TRUE); $langcode = 'fr'; $default_langcode = $this->langcodes[0]; diff --git a/core/modules/language/language.negotiation.inc b/core/modules/language/language.negotiation.inc index 00840e8..d130bdb 100644 --- a/core/modules/language/language.negotiation.inc +++ b/core/modules/language/language.negotiation.inc @@ -50,58 +50,6 @@ const LANGUAGE_NEGOTIATION_URL_DOMAIN = 'domain'; /** - * Return links for the URL language switcher block. - * - * Translation links may be provided by other modules. - */ -function language_switcher_url($type, $path) { - $languages = language_list(); - $links = array(); - - foreach ($languages as $language) { - $links[$language->id] = array( - 'href' => $path, - 'title' => $language->name, - 'language' => $language, - 'attributes' => array('class' => array('language-link')), - ); - } - - return $links; -} - -/** - * Return the session language switcher block. - */ -function language_switcher_session($type, $path) { - $param = \Drupal::config('language.negotiation')->get('session.parameter'); - $language_query = isset($_SESSION[$param]) ? $_SESSION[$param] : language($type)->id; - - $languages = language_list(); - $links = array(); - - $query = $_GET; - - foreach ($languages as $language) { - $langcode = $language->id; - $links[$langcode] = array( - 'href' => $path, - 'title' => $language->name, - 'attributes' => array('class' => array('language-link')), - 'query' => $query, - ); - if ($language_query != $langcode) { - $links[$langcode]['query'][$param] = $langcode; - } - else { - $links[$langcode]['attributes']['class'][] = ' session-active'; - } - } - - return $links; -} - -/** * Reads language prefixes and uses the langcode if no prefix is set. */ function language_negotiation_url_prefixes() { diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageNegotiationInfoTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageNegotiationInfoTest.php index 2c843dc..f8e71af 100644 --- a/core/modules/language/lib/Drupal/language/Tests/LanguageNegotiationInfoTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageNegotiationInfoTest.php @@ -144,7 +144,6 @@ protected function languageNegotiationUpdate($op = 'install') { } drupal_static_reset('language_types_info'); - drupal_static_reset('language_negotiation_info'); $function = "language_modules_{$op}ed"; if (function_exists($function)) { $function($modules); diff --git a/core/modules/language/tests/language_test/lib/Drupal/language_test/Plugin/LanguageNegotiation/LanguageNegotiationTest.php b/core/modules/language/tests/language_test/lib/Drupal/language_test/Plugin/LanguageNegotiation/LanguageNegotiationTest.php index 0f60de1..226e1fe 100644 --- a/core/modules/language/tests/language_test/lib/Drupal/language_test/Plugin/LanguageNegotiation/LanguageNegotiationTest.php +++ b/core/modules/language/tests/language_test/lib/Drupal/language_test/Plugin/LanguageNegotiation/LanguageNegotiationTest.php @@ -7,9 +7,6 @@ namespace Drupal\language_test\Plugin\LanguageNegotiation; -use Drupal\Component\Annotation\Plugin; -use Drupal\Core\Annotation\Translation; -use Drupal\Core\Language\Language; use Drupal\Core\Language\LanguageNegotiationMethodBase; use Symfony\Component\HttpFoundation\Request; @@ -17,11 +14,11 @@ * Class for identifying language from a selected language. * * @Plugin( - * id = LanguageNegotiationTest::METHOD_ID, + * id = "test_language_negotiation_method", * weight = -10, * name = @Translation("Test"), * description = @Translation("This is a test language negotiation method."), - * types = {Language::TYPE_CONTENT, "test_language_type", "fixed_test_language_type"} + * types = {Drupal\Core\Language\Language::TYPE_CONTENT, "test_language_type", "fixed_test_language_type"} * ) */ class LanguageNegotiationTest extends LanguageNegotiationMethodBase { diff --git a/core/modules/language/tests/language_test/lib/Drupal/language_test/Plugin/LanguageNegotiation/LanguageNegotiationTestTs.php b/core/modules/language/tests/language_test/lib/Drupal/language_test/Plugin/LanguageNegotiation/LanguageNegotiationTestTs.php index de3bb80..cef125c 100644 --- a/core/modules/language/tests/language_test/lib/Drupal/language_test/Plugin/LanguageNegotiation/LanguageNegotiationTestTs.php +++ b/core/modules/language/tests/language_test/lib/Drupal/language_test/Plugin/LanguageNegotiation/LanguageNegotiationTestTs.php @@ -7,16 +7,13 @@ namespace Drupal\language_test\Plugin\LanguageNegotiation; -use Drupal\Component\Annotation\Plugin; -use Drupal\Core\Annotation\Translation; -use Drupal\Core\Language\LanguageNegotiationMethodBase; use Symfony\Component\HttpFoundation\Request; /** * Class for identifying language from a selected language. * * @Plugin( - * id = Drupal\language_test\\Plugin\LanguageNegotiation\LanguageNegotiationTestTs::METHOD_ID, + * id = "test_language_negotiation_method_ts", * weight = -10, * name = @Translation("Type-specific test"), * description = @Translation("This is a test language negotiation method."),