Commit c582d6f2 authored by webchick's avatar webchick

Issue #1920888 by alexh58, YesCT: Fixed Add some JS to make the dependent...

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.
parent 089fd556
......@@ -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';
}
......
......@@ -2,6 +2,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.
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment