summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwebchick2013-03-10 06:18:48 (GMT)
committerwebchick2013-03-10 06:18:48 (GMT)
commitc582d6f21952bea0fc8bb688c18cd8b9c7e620b7 (patch)
treea80c401a76e2cce007d7acacdcb4ac23630e9b95
parent089fd55684d9411d48d8ffd47858770fb26e7667 (diff)
Issue #1920888 by alexh58, YesCT: Fixed Add some JS to make the dependent groups always checked (and readonly) when the master group is checked translatable.
-rw-r--r--core/modules/translation_entity/translation_entity.admin.inc17
-rw-r--r--core/modules/translation_entity/translation_entity.admin.js53
2 files changed, 69 insertions, 1 deletions
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..7f01944 100644
--- a/core/modules/translation_entity/translation_entity.admin.js
+++ b/core/modules/translation_entity/translation_entity.admin.js
@@ -3,6 +3,59 @@
"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() {
+ Drupal.behaviors.translationEntityDependentOptions.check($fields, $dependent_columns, $(this));
+ });
+
+ // Run the check function on first trigger of this behavior.
+ Drupal.behaviors.translationEntityDependentOptions.check($fields, $dependent_columns, false);
+ });
+ },
+ check: function($fields, $dependent_columns, $changed) {
+ // 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) {
+ var $element = $changed;
+
+ if(!$element) {
+ $fields.each(function() {
+ if($(this).val() == $column) {
+ $element = $(this);
+ return false;
+ }
+ });
+ }
+
+ if($element.is('input[value="' + $column + '"]:checked')) {
+ $fields.prop('checked', true).not($element).prop('disabled', true);
+ } else {
+ $fields.prop('disabled', false);
+ }
+ });
+ }
+};
+
+/**
* Makes field translatability inherit bundle translatability.
*/
Drupal.behaviors.translationEntity = {