summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwebchick2014-01-24 07:39:56 (GMT)
committerwebchick2014-01-24 07:39:56 (GMT)
commit3d984d28e9fb7146c532b275914f8870b9c288d5 (patch)
tree1e70d3871339653f95ed4d3a8c255df0a502005c
parentdc4327ba1d234903722b598358dcc53889efb8a2 (diff)
Issue #1831608 by smiletrl, penyaskito, swentel, jlbellido, vijaycs85, Gábor Hojtsy, piyuesh23, sun, YesCT | Lukas von Blarer: Show or hide the 'Make field translatable' checkbox on the add field form depending on translatability.
-rw-r--r--core/modules/content_translation/content_translation.module16
-rw-r--r--core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationSettingsTest.php40
-rw-r--r--core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php1
3 files changed, 56 insertions, 1 deletions
diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module
index 1f7afb5..b210091 100644
--- a/core/modules/content_translation/content_translation.module
+++ b/core/modules/content_translation/content_translation.module
@@ -825,13 +825,27 @@ function content_translation_field_extra_fields() {
* Implements hook_form_FORM_ID_alter() for 'field_ui_field_edit_form'.
*/
function content_translation_form_field_ui_field_edit_form_alter(array &$form, array &$form_state, $form_id) {
+ $field = $form['#field'];
+ $bundle = $form['#bundle'];
+ $bundle_is_translatable = content_translation_enabled($field->entity_type, $bundle);
$form['field']['translatable'] = array(
'#type' => 'checkbox',
'#title' => t('Users may translate this field.'),
- '#default_value' => $form['#field']->isTranslatable(),
+ '#default_value' => $field->isTranslatable(),
'#weight' => 20,
+ '#disabled' => !$bundle_is_translatable,
);
$form['#submit'][] = 'content_translation_form_field_ui_field_edit_form_submit';
+
+ // Provide helpful pointers for administrators.
+ if (\Drupal::currentUser()->hasPermission('administer content translation') && !$bundle_is_translatable) {
+ $toggle_url = url('admin/config/regional/content-language', array(
+ 'query' => drupal_get_destination(),
+ ));
+ $form['field']['translatable']['#description'] = t('To enable translation of this field, <a href="@language-settings-url">enable language support</a> for this type.', array(
+ '@language-settings-url' => $toggle_url,
+ ));
+ }
}
/**
diff --git a/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationSettingsTest.php b/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationSettingsTest.php
index 33ecd9a..ac8b55a 100644
--- a/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationSettingsTest.php
+++ b/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationSettingsTest.php
@@ -172,4 +172,44 @@ class ContentTranslationSettingsTest extends WebTestBase {
return $this->assertEqual(content_translation_enabled($entity_type, $bundle), $enabled, $message);
}
+ /**
+ * Tests that field instance setting depends on bundle translatability.
+ */
+ function testFieldTranslatableSettingsUI() {
+
+ // At least one field needs to be translatable to enable article for
+ // translation. Create an extra field to be used for this purpose.
+ $field = array(
+ 'name' => 'article_text',
+ 'entity_type' => 'node',
+ 'type' => 'text',
+ );
+ entity_create('field_entity', $field)->save();
+ $instance = array(
+ 'field_name' => 'article_text',
+ 'entity_type' => 'node',
+ 'bundle' => 'article',
+ );
+ entity_create('field_instance', $instance)->save();
+
+ // Tests that field instance doesn't have translatable setting if bundle
+ // is not translatable.
+ $path = 'admin/structure/types/manage/article/fields/node.article.body/field';
+ $this->drupalGet($path);
+ $this->assertText('To enable translation of this field, enable language support for this type.', 'No translatable setting for field.');
+
+ // Tests that field instance has translatable setting if bundle is
+ // translatable. Note: this field instance is not translatable when
+ // enable bundle translatability.
+ $edit = array(
+ 'entity_types[node]' => TRUE,
+ 'settings[node][article][settings][language][language_show]' => TRUE,
+ 'settings[node][article][translatable]' => TRUE,
+ 'settings[node][article][fields][article_text]' => TRUE,
+ );
+ $this->assertSettings('node', 'article', TRUE, $edit);
+ $this->drupalGet($path);
+ $this->assertNoText('To enable translation of this field, enable language support for this type.', 'No translatable setting for field.');
+ }
+
}
diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php
index 9edb9a4..7ed3992 100644
--- a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php
+++ b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php
@@ -91,6 +91,7 @@ class FieldEditForm extends FormBase {
$field = $this->instance->getField();
$form['#field'] = $field;
+ $form['#bundle'] = $this->instance->bundle;
$description = '<p>' . $this->t('These settings apply to the %field field everywhere it is used. These settings impact the way that data is stored in the database and cannot be changed once data has been created.', array('%field' => $this->instance->label())) . '</p>';