diff --git a/core/modules/language/config/language.negotiation.yml b/core/modules/language/config/language.negotiation.yml index 8ebea15..73ba546 100644 --- a/core/modules/language/config/language.negotiation.yml +++ b/core/modules/language/config/language.negotiation.yml @@ -6,3 +6,5 @@ url: en: '' domains: en: '' +customized_language_negotiation: + language_interface: language_interface diff --git a/core/modules/language/language.admin.inc b/core/modules/language/language.admin.inc index 1e6cdc4..c391b5b 100644 --- a/core/modules/language/language.admin.inc +++ b/core/modules/language/language.admin.inc @@ -376,7 +376,19 @@ function language_negotiation_configure_form() { foreach ($form['#language_types'] as $type) { language_negotiation_configure_form_table($form, $type); + $options[$type] = t('@name language', array('@name' => $form['#language_types_info'][$type]['name'])); } + $form['customized_language_negotiation'] = array( + '#type' => 'checkboxes', + '#title' => t('Customized language types'), + '#description' => t('Select the languages you want to customize the detection settings.'), + '#options' => $options, + '#default_value' => config('language.negotiation')->get('customized_language_negotiation'), + '#attached' => array( + 'library' => array(array('language', 'drupal.language.admin')), + ), + '#description' => t('Unchecked language types will get the same settings than %default_type.', array('%default_type' => $form['#language_types_info'][LANGUAGE_TYPE_INTERFACE]['name'])), + ); $form['actions'] = array('#type' => 'actions'); $form['actions']['submit'] = array( @@ -488,7 +500,7 @@ function language_negotiation_configure_form_table(&$form, $type) { */ function theme_language_negotiation_configure_form($variables) { $form = $variables['form']; - $output = ''; + $output = drupal_render($form['customized_language_negotiation']); foreach ($form['#language_types'] as $type) { $rows = array(); @@ -536,7 +548,7 @@ function theme_language_negotiation_configure_form($variables) { drupal_add_tabledrag("language-negotiation-methods-$type", 'order', 'sibling', "language-method-weight-$type"); - $output .= '
' . $title . $description . $table . '
'; + $output .= '
' . $title . $description . $table . '
'; } $output .= drupal_render_children($form); @@ -548,7 +560,15 @@ function theme_language_negotiation_configure_form($variables) { */ function language_negotiation_configure_form_submit($form, &$form_state) { $configurable_types = $form['#language_types']; + + // Always set the default language type LANGUAGE_TYPE_INTERFACE + $customized_language_negotiation = $form_state['values']['customized_language_negotiation']; + $customized_language_negotiation[LANGUAGE_TYPE_INTERFACE] = LANGUAGE_TYPE_INTERFACE; + config('language.negotiation') + ->set('customized_language_negotiation', $customized_language_negotiation) + ->save(); + $method_weights_default = array(); foreach ($configurable_types as $type) { $method_weights = array(); $enabled_methods = $form_state['values'][$type]['enabled']; @@ -561,8 +581,17 @@ 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); + if ($type == LANGUAGE_TYPE_INTERFACE) { + $method_weights_default = $method_weights; + } + if ($customized_language_negotiation[$type]) { + language_negotiation_set($type, $method_weights); + variable_set("language_negotiation_methods_weight_$type", $method_weights_input); + } + else { + language_negotiation_set($type, $method_weights_default); + variable_set("language_negotiation_methods_weight_$type", $form_state['values'][LANGUAGE_TYPE_INTERFACE]['weight']); + } } // Update non-configurable language types and the related language negotiation diff --git a/core/modules/language/language.admin.js b/core/modules/language/language.admin.js new file mode 100644 index 0000000..acb7d36 --- /dev/null +++ b/core/modules/language/language.admin.js @@ -0,0 +1,31 @@ +(function ($) { + +"use strict"; + +/** + * Makes language negotiation inherit user interface negotiation. + */ +Drupal.behaviors.negotiationLanguage = { + attach: function (context) { + var $context = $(context); + $('#edit-customized-language-negotiation-language-interface').attr('disabled', 'disabled'); + var toggleTable = function ($checkbox) { + var langtype = $checkbox.attr('name').replace('customized_language_negotiation[', '').replace(']', ''); + var $table = $('.table-' + langtype + '-wrapper'); + if ($checkbox.is(':checked')) { + $table.show(); + } + else { + $table.hide(); + } + }; + $('body').once('negotiation-language-admin-bind').on('click', '#edit-customized-language-negotiation :input', function (e) { + toggleTable($(e.target)); + }); + $('#edit-customized-language-negotiation :input').each(function (index, element) { + toggleTable($(element)); + }); + } +}; + +})(jQuery); diff --git a/core/modules/language/language.module b/core/modules/language/language.module index 3486ff4..6193522 100644 --- a/core/modules/language/language.module +++ b/core/modules/language/language.module @@ -835,6 +835,30 @@ function language_url_outbound_alter(&$path, &$options, $original_path) { } /** + * Implements hook_library_info(). + */ +function language_library_info() { + $path = drupal_get_path('module', 'language'); + $libraries['drupal.language.admin'] = array( + 'title' => 'Translation entity UI', + 'version' => VERSION, + 'js' => array( + $path . '/language.admin.js' => array(), + ), + 'css' => array( + $path . '/language.admin.css' => array(), + ), + 'dependencies' => array( + array('system', 'jquery'), + array('system', 'drupal'), + array('system', 'jquery.once'), + ), + ); + + return $libraries; +} + +/** * Returns language mappings between browser and Drupal language codes. * * @return array