summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2013-05-06 10:31:46 (GMT)
committer Alex Pott2013-05-06 10:31:46 (GMT)
commitcb4782ea137a86c5744f4bd854d3e62ed0b5d22a (patch)
tree9e2cce9179007b3b1c2731096c2e482c9e1be242
parentbe3667b3efc81bbe11e2226e1f92eec1db89631a (diff)
Issue #1977784 by YesCT, Gábor Hojtsy, EllaTheHarpy: Content language settings configuration page needs to determine what entities and bundles to include.
-rw-r--r--core/lib/Drupal/Core/Entity/Annotation/EntityType.php5
-rw-r--r--core/modules/language/language.admin.inc8
-rw-r--r--core/modules/language/language.module2
-rw-r--r--core/modules/translation_entity/translation_entity.admin.inc76
-rw-r--r--core/modules/translation_entity/translation_entity.module35
5 files changed, 77 insertions, 49 deletions
diff --git a/core/lib/Drupal/Core/Entity/Annotation/EntityType.php b/core/lib/Drupal/Core/Entity/Annotation/EntityType.php
index 95d97f0..30c8252 100644
--- a/core/lib/Drupal/Core/Entity/Annotation/EntityType.php
+++ b/core/lib/Drupal/Core/Entity/Annotation/EntityType.php
@@ -138,7 +138,10 @@ class EntityType extends Plugin {
public $static_cache = TRUE;
/**
- * Boolean indicating whether entities of this type have mutlilingual support.
+ * Boolean indicating whether entities of this type have multilingual support.
+ *
+ * At an entity level, this indicates language support and at a bundle level
+ * this indicates translation support.
*
* @var bool (optional)
*/
diff --git a/core/modules/language/language.admin.inc b/core/modules/language/language.admin.inc
index f59fb38..59f1efa 100644
--- a/core/modules/language/language.admin.inc
+++ b/core/modules/language/language.admin.inc
@@ -799,6 +799,8 @@ function language_content_settings_form(array $form, array $form_state, array $s
}
}
+ asort($labels);
+
$path = drupal_get_path('module', 'language');
$form = array(
'#labels' => $labels,
@@ -816,15 +818,15 @@ function language_content_settings_form(array $form, array $form_state, array $s
$form['settings'] = array('#tree' => TRUE);
- foreach ($supported as $entity_type) {
+ foreach ($labels as $entity_type => $label) {
$info = $entity_info[$entity_type];
$form['settings'][$entity_type] = array(
- '#title' => $labels[$entity_type],
+ '#title' => $label,
'#type' => 'container',
'#entity_type' => $entity_type,
'#theme' => 'language_content_settings_table',
- '#bundle_label' => isset($info['bundle_label']) ? $info['bundle_label'] : $labels[$entity_type],
+ '#bundle_label' => isset($info['bundle_label']) ? $info['bundle_label'] : $label,
'#states' => array(
'visible' => array(
':input[name="entity_types[' . $entity_type . ']"]' => array('checked' => TRUE),
diff --git a/core/modules/language/language.module b/core/modules/language/language.module
index 6bbb5a7..476246f 100644
--- a/core/modules/language/language.module
+++ b/core/modules/language/language.module
@@ -201,7 +201,7 @@ function language_theme() {
function language_entity_supported() {
$supported = array();
foreach (entity_get_info() as $entity_type => $info) {
- if (!empty($info['fieldable']) && !empty($info['translatable'])) {
+ if (!empty($info['translatable'])) {
$supported[$entity_type] = $entity_type;
}
}
diff --git a/core/modules/translation_entity/translation_entity.admin.inc b/core/modules/translation_entity/translation_entity.admin.inc
index 7aa91bf..8c184b5 100644
--- a/core/modules/translation_entity/translation_entity.admin.inc
+++ b/core/modules/translation_entity/translation_entity.admin.inc
@@ -72,32 +72,40 @@ function _translation_entity_form_language_content_settings_form_alter(array &$f
$dependent_options_settings = array();
foreach ($form['#labels'] as $entity_type => $label) {
+ $entity_info = entity_get_info($entity_type);
foreach (entity_get_bundles($entity_type) as $bundle => $bundle_info) {
- $form['settings'][$entity_type][$bundle]['translatable'] = array(
- '#type' => 'checkbox',
- '#default_value' => translation_entity_enabled($entity_type, $bundle),
- );
-
// Here we do not want the widget to be altered and hold also the "Enable
// translation" checkbox, which would be redundant. Hence we add this key
// to be able to skip alterations.
$form['settings'][$entity_type][$bundle]['settings']['language']['#translation_entity_skip_alter'] = TRUE;
- // @todo Exploit field definitions once all core entities and field types
- // are migrated to the Entity Field API.
- foreach (field_info_instances($entity_type, $bundle) as $field_name => $instance) {
- $field = field_info_field($field_name);
- $form['settings'][$entity_type][$bundle]['fields'][$field_name] = array(
- '#label' => $instance['label'],
- '#type' => 'checkbox',
- '#default_value' => $field['translatable'],
- );
- $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');
+ // Only show the checkbox to enable translation if the bundles in the
+ // entity might have fields and if there are fields to translate.
+ if (!empty($entity_info['fieldable'])) {
+ $fields = field_info_instances($entity_type, $bundle);
+ if ($fields) {
+ $form['settings'][$entity_type][$bundle]['translatable'] = array(
+ '#type' => 'checkbox',
+ '#default_value' => translation_entity_enabled($entity_type, $bundle),
+ );
+
+ // @todo Exploit field definitions once all core entities and field
+ // types are migrated to the Entity Field API.
+ foreach ($fields as $field_name => $instance) {
+ $field = field_info_field($field_name);
+ $form['settings'][$entity_type][$bundle]['fields'][$field_name] = array(
+ '#label' => $instance['label'],
+ '#type' => 'checkbox',
+ '#default_value' => $field['translatable'],
+ );
+ $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');
+ }
+ }
}
}
}
@@ -127,16 +135,26 @@ function _translation_entity_preprocess_language_content_settings_table(&$variab
foreach (element_children($element) as $bundle) {
$field_names = !empty($element[$bundle]['fields']) ? element_children($element[$bundle]['fields']) : array();
- $checkbox_id = $element[$bundle]['translatable']['#id'];
+ if (!empty($element[$bundle]['translatable'])) {
+ $checkbox_id = $element[$bundle]['translatable']['#id'];
+ }
$rows[$bundle] = $build['#rows'][$bundle];
- $translatable = array(
- 'data' => $element[$bundle]['translatable'],
- 'class' => array('translatable'),
- );
- array_unshift($rows[$bundle]['data'], $translatable);
+ if (!empty($element[$bundle]['translatable'])) {
+ $translatable = array(
+ 'data' => $element[$bundle]['translatable'],
+ 'class' => array('translatable'),
+ );
+ array_unshift($rows[$bundle]['data'], $translatable);
- $rows[$bundle]['data'][1]['data']['#prefix'] = '<label for="' . $checkbox_id . '">';
+ $rows[$bundle]['data'][1]['data']['#prefix'] = '<label for="' . $checkbox_id . '">';
+ }
+ else {
+ $translatable = array(
+ 'class' => array('untranslatable'),
+ );
+ array_unshift($rows[$bundle]['data'], $translatable);
+ }
foreach ($field_names as $field_name) {
$field_element = &$element[$bundle]['fields'][$field_name];
@@ -259,7 +277,9 @@ function translation_entity_form_language_content_settings_submit(array $form, a
// all of its fields will be not translatable.
foreach ($settings as $entity_type => &$entity_settings) {
foreach ($entity_settings as $bundle => &$bundle_settings) {
- $bundle_settings['translatable'] = $bundle_settings['translatable'] && $entity_types[$entity_type];
+ if (!empty($bundle_settings['translatable'])) {
+ $bundle_settings['translatable'] = $bundle_settings['translatable'] && $entity_types[$entity_type];
+ }
if (!empty($bundle_settings['fields'])) {
foreach ($bundle_settings['fields'] as $field_name => $translatable) {
$bundle_settings['fields'][$field_name] = $translatable && $bundle_settings['translatable'];
diff --git a/core/modules/translation_entity/translation_entity.module b/core/modules/translation_entity/translation_entity.module
index e77b39d..82bd66d 100644
--- a/core/modules/translation_entity/translation_entity.module
+++ b/core/modules/translation_entity/translation_entity.module
@@ -1009,23 +1009,26 @@ function translation_entity_preprocess_language_content_settings_table(&$variabl
function translation_entity_save_settings($settings) {
foreach ($settings as $entity_type => $entity_settings) {
foreach ($entity_settings as $bundle => $bundle_settings) {
- // Store bundle translatability.
- translation_entity_set_config($entity_type, $bundle, 'enabled', $bundle_settings['translatable']);
-
- // Store column translatability.
- if (!empty($bundle_settings['columns'])) {
- foreach ($bundle_settings['columns'] as $field_name => $column_settings) {
- $field = field_info_field($field_name);
- $instance = field_info_instance($entity_type, $field_name, $bundle);
- if ($field['translatable']) {
- $instance['settings']['translation_sync'] = $column_settings;
- }
- // If the field is untransltable we need to reset the sync settings to
- // their defaults.
- else {
- unset($instance['settings']['translation_sync']);
+ // The 'translatable' value is set only if it is possible to enable.
+ if (isset($bundle_settings['translatable'])) {
+ // Store whether a bundle has translation enabled or not.
+ translation_entity_set_config($entity_type, $bundle, 'enabled', $bundle_settings['translatable']);
+
+ // Store whether fields have translation enabled or not.
+ if (!empty($bundle_settings['columns'])) {
+ foreach ($bundle_settings['columns'] as $field_name => $column_settings) {
+ $field = field_info_field($field_name);
+ $instance = field_info_instance($entity_type, $field_name, $bundle);
+ if ($field['translatable']) {
+ $instance['settings']['translation_sync'] = $column_settings;
+ }
+ // If the field does not have translatable enabled we need to reset
+ // the sync settings to their defaults.
+ else {
+ unset($instance['settings']['translation_sync']);
+ }
+ field_update_instance($instance);
}
- field_update_instance($instance);
}
}
}