Commit cb4782ea authored by alexpott's avatar alexpott

Issue #1977784 by YesCT, Gábor Hojtsy, EllaTheHarpy: Content language settings...

Issue #1977784 by YesCT, Gábor Hojtsy, EllaTheHarpy: Content language settings configuration page needs to determine what entities and bundles to include.
parent be3667b3
......@@ -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)
*/
......
......@@ -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),
......
......@@ -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;
}
}
......
......@@ -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'];
......
......@@ -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);
}
}
}
......
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