diff --git a/core/modules/translation_entity/translation_entity.admin.css b/core/modules/translation_entity/translation_entity.admin.css
index 5f03b78..c39fc8a 100644
--- a/core/modules/translation_entity/translation_entity.admin.css
+++ b/core/modules/translation_entity/translation_entity.admin.css
@@ -27,3 +27,7 @@
#language-content-settings-form table .operations {
width: 75%;
}
+
+.form-item-default-language-language-show .description {
+ opacity: 0;
+}
\ No newline at end of file
diff --git a/core/modules/translation_entity/translation_entity.admin.js b/core/modules/translation_entity/translation_entity.admin.js
index 2f9f49f..b447353 100644
--- a/core/modules/translation_entity/translation_entity.admin.js
+++ b/core/modules/translation_entity/translation_entity.admin.js
@@ -33,4 +33,67 @@ 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);
+ }
+ };
+
})(jQuery);
diff --git a/core/modules/translation_entity/translation_entity.module b/core/modules/translation_entity/translation_entity.module
index b5108ed..16fa5a7 100644
--- a/core/modules/translation_entity/translation_entity.module
+++ b/core/modules/translation_entity/translation_entity.module
@@ -728,6 +728,20 @@ function translation_entity_language_configuration_element_process(array $elemen
if (empty($element['#translation_entity_skip_alter']) && user_access('administer entity translation')) {
$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'])) {
+ $element['langcode'] = array_merge_recursive($element['langcode'], array('#attributes' => array(
+ 'class' => array('langcode-select')
+ )));
+ }
$element['translation_entity'] = array(
'#type' => 'checkbox',
@@ -735,6 +749,7 @@ function translation_entity_language_configuration_element_process(array $elemen
'#default_value' => translation_entity_enabled($context['entity_type'], $context['bundle']),
'#element_validate' => array('translation_entity_language_configuration_element_validate'),
'#prefix' => '',
+ '#attributes' => array('class' => array('translation-enabled-checkbox')),
);
$form['#submit'][] = 'translation_entity_language_configuration_element_submit';
@@ -843,6 +858,17 @@ function translation_entity_preprocess_language_content_settings_table(&$variabl
array_unshift($rows[$bundle]['data'], $translatable);
$rows[$bundle]['data'][1]['data']['#prefix'] = '