Commit 8c44d48f authored by webchick's avatar webchick
Browse files

Issue #1877048 by nod_: Fixed Make Translation entity module JS follow newer core rules

parent 25ad0ea4
...@@ -25,9 +25,7 @@ function _translation_entity_form_language_content_settings_form_alter(array &$f ...@@ -25,9 +25,7 @@ function _translation_entity_form_language_content_settings_form_alter(array &$f
} }
$form['entity_types']['#default_value'] = $default; $form['entity_types']['#default_value'] = $default;
$path = drupal_get_path('module', 'translation_entity'); $form['#attached']['library'][] = array('translation_entity', 'drupal.translation_entity.admin');
$form['#attached']['css'][] = $path . '/translation_entity.admin.css';
$form['#attached']['js'][] = $path . '/translation_entity.admin.js';
foreach ($form['#labels'] as $entity_type => $label) { foreach ($form['#labels'] as $entity_type => $label) {
foreach (entity_get_bundles($entity_type) as $bundle) { foreach (entity_get_bundles($entity_type) as $bundle) {
......
...@@ -7,28 +7,28 @@ ...@@ -7,28 +7,28 @@
*/ */
Drupal.behaviors.translationEntity = { Drupal.behaviors.translationEntity = {
attach: function (context) { attach: function (context) {
var $context = $(context);
// Initially hide all field rows for non translatable bundles. // Initially hide all field rows for non translatable bundles.
var $input = $('table .bundle-settings .translatable :input', context); var $inputs = $context.find('table .bundle-settings .translatable :input');
$input.filter(':not(:checked)').once('translation-entity-admin-hide', function() { $inputs.filter(':not(:checked)').once('translation-entity-admin-hide', function () {
$(this).closest('.bundle-settings').nextUntil('.bundle-settings').hide(); $(this).closest('.bundle-settings').nextUntil('.bundle-settings').hide();
}); });
// When a bundle is made translatable all of its field instances should // When a bundle is made translatable all of its field instances should
// inherit this setting. Instead when it is made non translatable its field // inherit this setting. Instead when it is made non translatable its field
// instances are hidden, since their translatability no longer matters. // instances are hidden, since their translatability no longer matters.
$input.once('translation-entity-admin-bind', function() { $('body').once('translation-entity-admin-bind').on('click', 'table .bundle-settings .translatable :input', function (e) {
var $bundleTranslatable = $(this).click(function() { var $target = $(e.target);
var $bundleSettings = $bundleTranslatable.closest('.bundle-settings'); var $bundleSettings = $target.closest('.bundle-settings');
var $fieldSettings = $bundleSettings.nextUntil('.bundle-settings'); var $fieldSettings = $bundleSettings.nextUntil('.bundle-settings');
if ($bundleTranslatable.is(':checked')) { if ($target.is(':checked')) {
$bundleSettings.find('.operations :input[name$="[language_hidden]"]').attr('checked', false); $bundleSettings.find('.operations :input[name$="[language_hidden]"]').attr('checked', false);
$fieldSettings.find('.translatable :input').attr('checked', true); $fieldSettings.find('.translatable :input').attr('checked', true);
$fieldSettings.show(); $fieldSettings.show();
} }
else { else {
$fieldSettings.hide(); $fieldSettings.hide();
} }
});
}); });
} }
}; };
......
...@@ -254,6 +254,30 @@ function translation_entity_add_access(EntityInterface $entity, Language $source ...@@ -254,6 +254,30 @@ function translation_entity_add_access(EntityInterface $entity, Language $source
return $source->langcode != $target->langcode && isset($languages[$source->langcode]) && isset($languages[$target->langcode]) && !isset($translations[$target->langcode]) && translation_entity_access($entity, $target->langcode); return $source->langcode != $target->langcode && isset($languages[$source->langcode]) && isset($languages[$target->langcode]) && !isset($translations[$target->langcode]) && translation_entity_access($entity, $target->langcode);
} }
/**
* Implements hook_library_info().
*/
function translation_entity_library_info() {
$path = drupal_get_path('module', 'translation_entity');
$libraries['drupal.translation_entity.admin'] = array(
'title' => 'Translation entity UI',
'version' => VERSION,
'js' => array(
$path . '/translation_entity.admin.js' => array(),
),
'css' => array(
$path . '/translation_entity.admin.css' => array(),
),
'dependencies' => array(
array('system', 'jquery'),
array('system', 'drupal'),
array('system', 'jquery.once'),
),
);
return $libraries;
}
/** /**
* Returns the key name used to store the configuration item. * Returns the key name used to store the configuration item.
* *
......
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