diff --git a/core/includes/language.inc b/core/includes/language.inc index 5fae151..1f7d392 100644 --- a/core/includes/language.inc +++ b/core/includes/language.inc @@ -178,13 +178,10 @@ function language_types_info() { function language_types_get_configurable($stored = TRUE) { $configurable = &drupal_static(__FUNCTION__); - if ($stored && !isset($configurable)) { - $types = variable_get('language_types', language_types_get_default()); - $configurable = array_keys(array_filter($types)); - } - - if (!$stored) { - return array_keys(array_filter(config('system.language.types')->get('configurable'))); + if (!$stored || !isset($configurable)) { + $configurable = config('system.language.types')->get('configurable'); + $configurable = is_null($configurable) ? array() : array_keys(array_filter($configurable)); + return $configurable; } return $configurable; @@ -208,27 +205,38 @@ function language_types_disable($types) { /** * Updates the language type configuration. + * + * @param array $configurable + * The configuration object containing the user defined preferences for + * language type customizability. If it's not provided it will be loaded from + * configuration. */ -function language_types_set() { +function language_types_set($configurable = NULL) { + language_negotiation_include(); // Ensure that we are getting the defined language negotiation information. An // invocation of module_enable() or module_disable() could outdate the cached // information. drupal_static_reset('language_types_info'); drupal_static_reset('language_negotiation_info'); + // In case the $configurable array is not passed in load it from + // configuration. + if (is_null($configurable)) { + $configurable = config('system.language.types')->get('configurable'); + } + // Determine which language types are configurable and which not by checking // whether the 'fixed' key is defined. Non-configurable (fixed) language types // have their language negotiation settings stored there. $language_types = array(); $negotiation_info = language_negotiation_info(); - $configurable = config('system.language.types')->get('configurable'); foreach (language_types_info() as $type => $info) { - if (!empty($info['locked'])) { + if ($locked = !empty($info['locked'])) { // For locked languages the configurability is set based on the presence // of the default settings. $configurable[$type] = empty($info['fixed']); - if (isset($info['fixed'])) { - $language_types[$type] = FALSE; + $language_types[$type] = !$locked; + if (!$configurable[$type]) { $method_weights = array(); foreach ($info['fixed'] as $weight => $method_id) { if (isset($negotiation_info[$method_id])) { @@ -239,7 +247,15 @@ function language_types_set() { } } else { - $language_types[$type] = TRUE; + // For unlocked languages read the configurable array. + $language_types[$type] = !empty($configurable[$type]); + if (!$language_types[$type] && empty($info['fixed'])) { + // If the language is non configurable and there is no default + // language negotiation setting then provide one. + $method_weights = array(LANGUAGE_NEGOTIATION_INTERFACE); + $method_weights = array_flip($method_weights); + language_negotiation_set($type, $method_weights); + } } } diff --git a/core/modules/language/language.admin.inc b/core/modules/language/language.admin.inc index d15a768..1904a62 100644 --- a/core/modules/language/language.admin.inc +++ b/core/modules/language/language.admin.inc @@ -6,7 +6,6 @@ */ use Drupal\Core\Language\Language; -// use Drupal\block\Plugin\Type\BlockManager; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** @@ -402,7 +401,7 @@ function language_negotiation_configure_form_table(&$form, $type) { $table_form['configurable'] = array( '#type' => 'checkbox', '#title' => t('Customize %language_name language detection to differ from User interface text language detection settings.', array('%language_name' => $info['name'])), - '#default_value' => empty($configurable[$type]) ? FALSE : $configurable[$type], + '#default_value' => !empty($configurable[$type]), '#attributes' => array('class' => array('language-customization-checkbox')), '#attached' => array( 'js' => array(drupal_get_path('module', 'language') . '/language.admin.js' => array('type' => 'file')), @@ -578,19 +577,16 @@ function language_negotiation_configure_form_submit($form, &$form_state) { language_negotiation_set($type, $method_weights); variable_set("language_negotiation_methods_weight_$type", $method_weights_input); } - config('system.language.types') - ->set('configurable', $configurable) - ->save(); + + // Update non-configurable language types and the related language negotiation + // configuration. + language_types_set($configurable); // Clear the block's cache to change the block name when there is only one - // language switcher block. + drupal_container()->get('plugin.manager.block')->clearCachedDefinitions(); // $block_manager = new BlockManager(array('Drupal\language\Plugin\Derivative\LanguageBlock')); // $block_manager->clearCachedDefinitions(); - // Update non-configurable language types and the related language negotiation - // configuration. - language_types_set(); - $form_state['redirect'] = 'admin/config/regional/language/detection'; drupal_set_message(t('Language negotiation configuration saved.')); } diff --git a/core/modules/language/language.module b/core/modules/language/language.module index 51e18c9..7e673b2 100644 --- a/core/modules/language/language.module +++ b/core/modules/language/language.module @@ -625,7 +625,6 @@ function language_language_types_info() { LANGUAGE_TYPE_CONTENT => array( 'name' => t('Content'), 'description' => t('Order of language detection methods for content. If a version of content is available in the detected language, it will be displayed.'), - 'fixed' => array(LANGUAGE_NEGOTIATION_INTERFACE), 'locked' => TRUE, ), LANGUAGE_TYPE_URL => array( @@ -913,21 +912,3 @@ function language_system_regional_settings_form_submit($form, &$form_state) { $language->default = TRUE; language_save($language); } - -/** - * Implement hook_language_types_info_alter(). - */ -function language_language_types_info_alter(&$language_types) { - language_negotiation_include(); - $configurable = config('system.languages.types')->get('configurable'); - foreach ($language_types as $type => $info) { - if (empty($info['locked']) && empty($configurable[$type]) && empty($info['fixed'])) { - // For unlocked and non-configurable languages a default language - // negotiation is set in case there is none. - $language_types[$type]['fixed'] = array(LANGUAGE_NEGOTIATION_INTERFACE); - } - } - // All modules altering the locked flag or the fixed settings for a locked - // language must ensure that run before this one or update the configurable - // language types config object by itself. -} \ No newline at end of file diff --git a/core/modules/language/lib/Drupal/language/Plugin/Derivative/LanguageBlock.php b/core/modules/language/lib/Drupal/language/Plugin/Derivative/LanguageBlock.php index 0344455..d27ca3e 100644 --- a/core/modules/language/lib/Drupal/language/Plugin/Derivative/LanguageBlock.php +++ b/core/modules/language/lib/Drupal/language/Plugin/Derivative/LanguageBlock.php @@ -47,7 +47,7 @@ public function getDerivativeDefinitions(array $base_plugin_definition) { // If there is just one configurable type then change the title of the // block. if (count($configurable_types) == 1) { - $this->derivatives[reset($configurable_types)]['subject'] = t('Language switcher'); + $this->derivatives[reset($configurable_types)]['admin_label'] = t('Language switcher'); } return $this->derivatives; } diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageNegotiationInfoTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageNegotiationInfoTest.php index e251483..e96a3d1 100644 --- a/core/modules/language/lib/Drupal/language/Tests/LanguageNegotiationInfoTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageNegotiationInfoTest.php @@ -162,11 +162,6 @@ protected function checkFixedLanguageTypes() { foreach (language_types_info() as $type => $info) { if (empty($configurable[$type]) && isset($info['fixed'])) { $negotiation = variable_get("language_negotiation_$type", array()); - // Non configurable languages without negotiation settings should - // default to LANGUAGE_NEGOTIATION_INTERFACE. - if (empty($negotiation)) { - $negotiation = array(LANGUAGE_NEGOTIATION_INTERFACE); - } $equal = count($info['fixed']) == count($negotiation); while ($equal && list($id) = each($negotiation)) { list(, $info_id) = each($info['fixed']); diff --git a/core/modules/system/config/system.language.types.yml b/core/modules/system/config/system.language.types.yml index 76aaf80..114fef6 100644 --- a/core/modules/system/config/system.language.types.yml +++ b/core/modules/system/config/system.language.types.yml @@ -2,4 +2,4 @@ configurable: language_interface: '1' language_content: '0' - language_url: '0' \ No newline at end of file + language_url: '0'