diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module index 1f7afb5d58c106451ea7db74a512148b008341e4..b210091c2e4c6907fda8622bc7423dd24e2bb97a 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 33ecd9a75871e5409f0f75d4cd5271422a557845..ac8b55a490e43ffb24067d79814a328dede7e007 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 @@ protected function assertSettings($entity_type, $bundle, $enabled, $edit) { 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 9edb9a4dafe9547e4eac7a85c3e38e592cf5b64e..7ed39929b869fd12ba1f8fbc48da0a7d1402b053 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 @@ public function buildForm(array $form, array &$form_state, FieldInstanceInterfac $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>';