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 b078d23..2854084 100644
--- a/core/modules/language/language.admin.inc
+++ b/core/modules/language/language.admin.inc
@@ -376,7 +376,18 @@ 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'),
+ '#options' => $options,
+ '#default_value' => config('language.negotiation')->get('customized_language_negotiation'),
+ '#attached' => array(
+ 'js' => array(drupal_get_path('module', 'language') . '/language.admin.js' => array('type' => 'file')),
+ ),
+ '#description' => t('Unchecked language types will get the same settings as %default_type language.', array('%default_type' => $form['#language_types_info'][LANGUAGE_TYPE_INTERFACE]['name'])),
+ );
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
@@ -488,7 +499,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 +547,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);
@@ -549,6 +560,13 @@ 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();
+
foreach ($configurable_types as $type) {
$method_weights = array();
$enabled_methods = $form_state['values'][$type]['enabled'];
diff --git a/core/modules/language/language.admin.js b/core/modules/language/language.admin.js
new file mode 100644
index 0000000..0327d9b
--- /dev/null
+++ b/core/modules/language/language.admin.js
@@ -0,0 +1,45 @@
+(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');
+ var $iface_weight = $(':input[name="language_content[weight][language-interface]"]', $table);
+ var $iface_enable = $('#edit-language-content-enabled-language-interface', $table);
+ var weights = $(':input[name^="language_content[weight]"]', $table).map(function (index, element) { return parseInt($(element).val()); }).get();
+ if (typeof($iface_weight.data('initial-value')) === 'undefined') {
+ $iface_weight.data('initial-value', $iface_weight.val());
+ };
+ if ($checkbox.is(':checked')) {
+ $iface_weight.val($iface_weight.data('initial-value'));
+ $iface_enable.attr('disabled', false);
+ $table.find('tbody tr').show();
+ }
+ else {
+ $iface_weight.val(Math.min.apply(null, weights) - 1);
+ $table.find('tbody tr').hide();
+ $iface_enable.attr('disabled', true).closest('tr').show();
+ }
+ };
+ $('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));
+ });
+ $('#language-negotiation-configure-form').submit(function () {
+ // Re-enable the language-interface checkboxes to avoid sending false.
+ $('#edit-language-content-enabled-language-interface').attr('disabled', false);
+ });
+ }
+};
+
+})(jQuery);