diff --git a/core/modules/translation_entity/translation_entity.admin.js b/core/modules/translation_entity/translation_entity.admin.js index d9c132a..fd89735 100644 --- a/core/modules/translation_entity/translation_entity.admin.js +++ b/core/modules/translation_entity/translation_entity.admin.js @@ -105,65 +105,72 @@ Drupal.behaviors.translationEntity = { /** * Removes unusable locked languages when not showing language selector. + * * This behavior gets attached on the relevant entity edition form and * the translation entity summary form. */ - Drupal.behaviors.lockedSelector = { - attach: function (context) { - var $context = $(context); - - // Declare the function in scope and reuse it later. - var filterAvailableLanguages = function ($languageSelector, $checkbox, $translatable) { - // Get the list of all languages and unlocked languages based on the original - // language selector options. - var $originalOptions = $languageSelector.data('originalOptions'); - if (typeof($originalOptions) !== 'undefined') { - var $unlockedOptions = $originalOptions.filter(function (index) { return !/^- .* -$/.test(this.text); }); - if ($translatable.size() == 0 || $translatable.is(':checked')) { - if ($checkbox.is(':checked')) { - $languageSelector.html($originalOptions); - $checkbox.siblings('.description').css('opacity', 0); - } - else { - $languageSelector.html($unlockedOptions); - $checkbox.siblings('.description').css('opacity', 1); - } - } - else { - $languageSelector.html($originalOptions); - $checkbox.siblings('.description').css('opacity', 0); - } - }; - }; - - var processSelectors = function ($container) { - if ($container.size()) { - // Store the data about original options in the language selector - // Do it only once to avoid losing options - $container.once('locked-selector-options').each(function (index, element) { - $('.langcode-select', element).data('originalOptions', $('option', $('.langcode-select', element))); - }); - $container.each(function (index, element) { - var $languageSelector = $('.langcode-select', element); - var $checkbox = $('.language-show-checkbox', element); - - // Execute the function at the beginning and whenever the relevant checkbox - // is clicked - $checkbox.on('click', function (e) { - filterAvailableLanguages($languageSelector, $checkbox, $translatable); - }); - filterAvailableLanguages($languageSelector, $checkbox, $translatable); - }); - }; - }; - - // Determine the kind of form we are dealing with - var $container = $('.bundle-settings .operations, .details-wrapper', context); - var $translatable = $('.translation-enabled-checkbox').once('locked-selector-options').on('click', function (e) { - processSelectors($container); - }); - processSelectors($container); - } - }; +Drupal.behaviors.lockedSelector = { + attach: function (context) { + var $context = $(context); + + // A custom message for the changed language options. + Drupal.theme.tableOptionsChangedWarning = function () { + return '
'; + }; + + // Declare the function in scope and reuse it later. + var filterAvailableLanguages = function ($languageSelector, $checkbox, $translatable) { + // Get the list of all languages and unlocked languages based on the original + // language selector options. + var $originalOptions = $languageSelector.data('originalOptions'); + if (typeof($originalOptions) !== 'undefined') { + var $unlockedOptions = $originalOptions.filter(function (index) { return !/^- .* -$/.test(this.text); }); + if ($translatable.size() == 0 || $translatable.is(':checked')) { + if ($checkbox.is(':checked')) { + $languageSelector.html($originalOptions).siblings('.description').find('.hidden-languages').hide(); + } + else { + // Warn the user if a locked language was selected. + if (/^- .* -$/.test($languageSelector.find(':selected').text())) { + $(Drupal.theme('tableOptionsChangedWarning')).insertBefore($('.form-type-vertical-tabs')).hide().fadeIn('slow'); + }; + $languageSelector.html($unlockedOptions).siblings('.description').find('.hidden-languages').show(); + } + } + else { + $languageSelector.html($originalOptions).siblings('.description').find('.hidden-languages').hide(); + } + }; + }; + + var processSelectors = function ($container) { + if ($container.size()) { + // Store the data about original options in the language selector + // Do it only once to avoid losing options + $container.once('locked-selector-options').each(function (index, element) { + $('.langcode-select', element).data('originalOptions', $('option', $('.langcode-select', element))); + }); + $container.each(function (index, element) { + var $languageSelector = $('.langcode-select', element); + var $checkbox = $('.language-show-checkbox', element); + + // Execute the function at the beginning and whenever the relevant checkbox + // is clicked + $checkbox.on('click', function (e) { + filterAvailableLanguages($languageSelector, $checkbox, $translatable); + }); + filterAvailableLanguages($languageSelector, $checkbox, $translatable); + }); + }; + }; + + // Determine the kind of form we are dealing with + var $container = $('.bundle-settings .operations, .details-wrapper', context); + var $translatable = $('.translation-enabled-checkbox').once('locked-selector-options').on('click', function (e) { + processSelectors($container); + }); + processSelectors($container); + } +}; })(jQuery); diff --git a/core/modules/translation_entity/translation_entity.module b/core/modules/translation_entity/translation_entity.module index a26bb02..d903e10 100644 --- a/core/modules/translation_entity/translation_entity.module +++ b/core/modules/translation_entity/translation_entity.module @@ -921,15 +921,17 @@ function translation_entity_language_configuration_element_process(array $elemen $form_state['translation_entity']['key'] = $element['#name']; $context = $form_state['language'][$element['#name']]; $element['#attached']['library'][] = array('translation_entity', 'drupal.translation_entity.admin'); - // Description only visible if the bundle is translatable and the - // language selector is shown - $element['language_show']['#description'] = t('Some default language options are hidden if the language selector is not shown and translation is enabled.'); - - // Adds CSS classes for easier JS selection - $element['language_show'] = array_merge_recursive($element['language_show'], array('#attributes' => array( - 'class' => array('language-show-checkbox') - ))); + + if (isset($element['langcode'])) { + // Adds CSS classes for easier JS selection + $element['language_show'] = array_merge_recursive($element['language_show'], array('#attributes' => array( + 'class' => array('language-show-checkbox') + ))); + } if (isset($element['langcode'])) { + // Description only visible if the bundle is translatable and the + // language selector is shown + $element['langcode']['#description'] .= ' ' . t('Some default language options are hidden if the language selector is not shown and translation is enabled.') . ''; $element['langcode'] = array_merge_recursive($element['langcode'], array('#attributes' => array( 'class' => array('langcode-select') )));