Commit 3d984d28 authored by webchick's avatar webchick

Issue #1831608 by smiletrl, penyaskito, swentel, jlbellido, vijaycs85, Gábor...

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.
parent dc4327ba
......@@ -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,
));
}
}
/**
......
......@@ -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.');
}
}
......@@ -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>';
......
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