3 * Content Translation admin behaviors.
6 (function ($, Drupal, drupalSettings) {
8 * Forces applicable options to be checked as translatable.
10 * @type {Drupal~behavior}
12 * @prop {Drupal~behaviorAttach} attach
13 * Attaches content translation dependent options to the UI.
15 Drupal.behaviors.contentTranslationDependentOptions = {
17 const $context = $(context);
18 const options = drupalSettings.contentTranslationDependentOptions;
20 let dependent_columns;
22 function fieldsChangeHandler($fields, dependent_columns) {
24 Drupal.behaviors.contentTranslationDependentOptions.check($fields, dependent_columns, $(e.target));
28 // We're given a generic name to look for so we find all inputs containing
29 // that name and copy over the input values that require all columns to be
31 if (options && options.dependent_selectors) {
32 for (const field in options.dependent_selectors) {
33 if (options.dependent_selectors.hasOwnProperty(field)) {
34 $fields = $context.find(`input[name^="${field}"]`);
35 dependent_columns = options.dependent_selectors[field];
37 $fields.on('change', fieldsChangeHandler($fields, dependent_columns));
38 Drupal.behaviors.contentTranslationDependentOptions.check($fields, dependent_columns);
43 check($fields, dependent_columns, $changed) {
44 let $element = $changed;
47 function filterFieldsList(index, field) {
48 return $(field).val() === column;
51 // A field that has many different translatable parts can also define one
52 // or more columns that require all columns to be translatable.
53 for (const index in dependent_columns) {
54 if (dependent_columns.hasOwnProperty(index)) {
55 column = dependent_columns[index];
58 $element = $fields.filter(filterFieldsList);
61 if ($element.is(`input[value="${column}"]:checked`)) {
62 $fields.prop('checked', true)
63 .not($element).prop('disabled', true);
66 $fields.prop('disabled', false);
74 * Makes field translatability inherit bundle translatability.
76 * @type {Drupal~behavior}
78 * @prop {Drupal~behaviorAttach} attach
79 * Attaches content translation behavior.
81 Drupal.behaviors.contentTranslation = {
83 // Initially hide all field rows for non translatable bundles and all
84 // column rows for non translatable fields.
85 $(context).find('table .bundle-settings .translatable :input').once('translation-entity-admin-hide').each(function () {
86 const $input = $(this);
87 const $bundleSettings = $input.closest('.bundle-settings');
88 if (!$input.is(':checked')) {
89 $bundleSettings.nextUntil('.bundle-settings').hide();
92 $bundleSettings.nextUntil('.bundle-settings', '.field-settings').find('.translatable :input:not(:checked)').closest('.field-settings').nextUntil(':not(.column-settings)').hide();
96 // When a bundle is made translatable all of its fields should inherit
97 // this setting. Instead when it is made non translatable its fields are
98 // hidden, since their translatability no longer matters.
99 $('body').once('translation-entity-admin-bind').on('click', 'table .bundle-settings .translatable :input', (e) => {
100 const $target = $(e.target);
101 const $bundleSettings = $target.closest('.bundle-settings');
102 const $settings = $bundleSettings.nextUntil('.bundle-settings');
103 const $fieldSettings = $settings.filter('.field-settings');
104 if ($target.is(':checked')) {
105 $bundleSettings.find('.operations :input[name$="[language_alterable]"]').prop('checked', true);
106 $fieldSettings.find('.translatable :input').prop('checked', true);
113 .on('click', 'table .field-settings .translatable :input', (e) => {
114 const $target = $(e.target);
115 const $fieldSettings = $target.closest('.field-settings');
116 const $columnSettings = $fieldSettings.nextUntil('.field-settings, .bundle-settings');
117 if ($target.is(':checked')) {
118 $columnSettings.show();
121 $columnSettings.hide();
126 }(jQuery, Drupal, drupalSettings));