From 5343b508eea3bbc384defaa9ba42794d3c08de3f Mon Sep 17 00:00:00 2001 From: alexh58 Date: Fri, 1 Mar 2013 17:44:39 -0500 Subject: [PATCH] JS to make title and alt fields checked if the file itself is translatable See #1920888 --- .../translation_entity.admin.inc | 17 ++++++++- .../translation_entity/translation_entity.admin.js | 39 ++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/core/modules/translation_entity/translation_entity.admin.inc b/core/modules/translation_entity/translation_entity.admin.inc index 0e2316b..2537c84 100644 --- a/core/modules/translation_entity/translation_entity.admin.inc +++ b/core/modules/translation_entity/translation_entity.admin.inc @@ -31,11 +31,19 @@ function translation_entity_field_sync_widget(array $field, FieldInstance $insta $default[$group] = !empty($info['translatable']) ? $group : FALSE; } + $settings = array('dependent_selectors' => array('instance[settings][translation_sync]' => array('file'))); + $element = array( '#type' => 'checkboxes', '#title' => t('Translatable elements'), '#options' => $options, '#default_value' => !empty($instance['settings']['translation_sync']) ? $instance['settings']['translation_sync'] : $default, + '#attached' => array( + 'js' => array( + array('data' => drupal_get_path('module', 'translation_entity') . '/translation_entity.admin.js', 'type' => 'file'), + array('data' => array('translationEntityDependentOptions' => $settings), 'type' => 'setting'), + ), + ), ); } @@ -59,7 +67,9 @@ function _translation_entity_form_language_content_settings_form_alter(array &$f $form['entity_types']['#default_value'] = $default; $form['#attached']['library'][] = array('translation_entity', 'drupal.translation_entity.admin'); + $form['#attached']['js'][] = array('data' => drupal_get_path('module', 'translation_entity') . '/translation_entity.admin.js', 'type' => 'file'); + $dependent_options_settings = array(); foreach ($form['#labels'] as $entity_type => $label) { foreach (entity_get_bundles($entity_type) as $bundle => $bundle_info) { $form['settings'][$entity_type][$bundle]['translatable'] = array( @@ -84,11 +94,16 @@ function _translation_entity_form_language_content_settings_form_alter(array &$f $column_element = translation_entity_field_sync_widget($field, $instance); if ($column_element) { $form['settings'][$entity_type][$bundle]['columns'][$field_name] = $column_element; + + if(isset($column_element['#options']['file'])) { + $dependent_options_settings["settings[{$entity_type}][{$bundle}][columns][{$field_name}]"] = array('file'); + } } } } } - + $settings = array('dependent_selectors' => $dependent_options_settings); + $form['#attached']['js'][] = array('data' => array('translationEntityDependentOptions' => $settings), 'type' => 'setting'); $form['#validate'][] = 'translation_entity_form_language_content_settings_validate'; $form['#submit'][] = 'translation_entity_form_language_content_settings_submit'; } diff --git a/core/modules/translation_entity/translation_entity.admin.js b/core/modules/translation_entity/translation_entity.admin.js index bf253a1..9647282 100644 --- a/core/modules/translation_entity/translation_entity.admin.js +++ b/core/modules/translation_entity/translation_entity.admin.js @@ -3,6 +3,45 @@ "use strict"; /** + * Forces applicable options to be checked as translatable. + */ +Drupal.behaviors.translationEntityDependentOptions = { + attach: function (context, settings) { + var $options = settings.translationEntityDependentOptions; + var $collections = []; + + // We're given a generic name to look for so we find all inputs + // containing that name and copy over the input values that + // require all columns to be translatable. + if ($options.dependent_selectors) { + $.each($options.dependent_selectors, function($field, $dependent_columns) { + $collections.push({ elements : $(context).find('input[name^="' + $field + '"]'), dependent_columns : $dependent_columns }); + }); + } + + $.each($collections, function($index, $collection) { + var $fields = $collection.elements; + var $dependent_columns = $collection.dependent_columns; + + $fields.change(function() { + var $changed = $(this); + + // A field that has many different translatable parts can + // also define one or more columns that require all columns + // to be translatable. + $.each($dependent_columns, function($index, $column) { + if($changed.is('input[value="' + $column + '"]:checked')) { + $fields.prop('checked', true).not($changed).prop('disabled', true); + } else { + $fields.prop('disabled', false); + } + }); + }); + }); + } +}; + +/** * Makes field translatability inherit bundle translatability. */ Drupal.behaviors.translationEntity = { -- 1.7.10.2 (Apple Git-33)