Commit 942df46a authored by alexpott's avatar alexpott

Issue #2401497 by plach: Field UI creates fields that can never be translated

parent 9e919411
......@@ -9,7 +9,6 @@
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\content_translation\Tests\ContentTranslationUITest;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Tests the Comment Translation UI.
......@@ -70,16 +69,6 @@ protected function getTranslatorPermissions() {
return array_merge(parent::getTranslatorPermissions(), array('post comments', 'administer comments', 'access comments'));
}
/**
* Overrides \Drupal\content_translation\Tests\ContentTranslationUITest::setupTestFields().
*/
function setupTestFields() {
parent::setupTestFields();
$field_storage = FieldStorageConfig::loadByName('comment', 'comment_body');
$field_storage->translatable = TRUE;
$field_storage->save();
}
/**
* Overrides \Drupal\content_translation\Tests\ContentTranslationUITest::createEntity().
*/
......
......@@ -7,7 +7,6 @@
namespace Drupal\comment\Tests\Views;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\language\Entity\ConfigurableLanguage;
/**
......@@ -44,12 +43,6 @@ function setUp() {
ConfigurableLanguage::createFromLangcode('fr')->save();
ConfigurableLanguage::createFromLangcode('es')->save();
// Make the comment body field translatable. The title is already
// translatable by definition.
$field_storage = FieldStorageConfig::loadByName('comment', 'comment_body');
$field_storage->translatable = TRUE;
$field_storage->save();
// Set up comment titles.
$this->commentTitles = array(
'en' => 'Food in Paris',
......
......@@ -225,26 +225,21 @@ protected function assertSettings($entity_type, $bundle, $enabled, $edit) {
* Tests that field 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_storage = array(
'field_name' => 'article_text',
'entity_type' => 'node',
'type' => 'text',
);
entity_create('field_storage_config', $field_storage)->save();
$field = array(
// translation. Create an extra field to be used for this purpose. We use
// the UI to test our form alterations.
$edit = array(
'new_storage_type' => 'text',
'label' => 'Test',
'field_name' => 'article_text',
'entity_type' => 'node',
'bundle' => 'article',
);
entity_create('field_config', $field)->save();
$this->drupalPostForm('admin/structure/types/manage/article/fields/add-field', $edit, 'Save and continue');
// Tests that field doesn't have translatable setting if bundle is not
// translatable.
$path = 'admin/structure/types/manage/article/fields/node.article.body';
$path = 'admin/structure/types/manage/article/fields/node.article.field_article_text';
$this->drupalGet($path);
$this->assertFieldByXPath('//input[@id="edit-field-translatable" and @disabled="disabled"]');
$this->assertText('To configure translation for this field, enable language support for this type.', 'No translatable setting for field.');
// Tests that field has translatable setting if bundle is translatable.
......@@ -253,11 +248,12 @@ function testFieldTranslatableSettingsUI() {
'entity_types[node]' => TRUE,
'settings[node][article][settings][language][language_alterable]' => TRUE,
'settings[node][article][translatable]' => TRUE,
'settings[node][article][fields][article_text]' => TRUE,
'settings[node][article][fields][field_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.');
$this->assertFieldByXPath('//input[@id="edit-field-translatable" and not(@disabled) and @checked="checked"]');
$this->assertNoText('To enable translation of this field, enable language support for this type.', 'Translatable setting for field available.');
}
/**
......
......@@ -62,14 +62,19 @@ public function testFieldTranslatableArticle() {
$path = 'admin/config/regional/content-language';
$this->drupalGet($path);
// Check comment checkbox.
$this->assertFieldByXPath("//input[@id='edit-settings-node-article-fields-comment' and @checked='checked']");
// Check content block fields.
$this->assertFieldByXPath("//input[@id='edit-settings-block-content-basic-fields-body' and @checked='checked']");
// Check image checkbox.
$this->assertFieldByXPath("//input[@id='edit-settings-node-article-fields-field-image' and @checked='checked']");
// Check comment fields.
$this->assertFieldByXPath("//input[@id='edit-settings-comment-comment-fields-comment-body' and @checked='checked']");
// Check tag checkbox.
// Check node fields.
$this->assertFieldByXPath("//input[@id='edit-settings-node-article-fields-comment' and @checked='checked']");
$this->assertFieldByXPath("//input[@id='edit-settings-node-article-fields-field-image' and @checked='checked']");
$this->assertFieldByXPath("//input[@id='edit-settings-node-article-fields-field-tags' and @checked='checked']");
// Check user fields.
$this->assertFieldByXPath("//input[@id='edit-settings-user-user-fields-user-picture' and @checked='checked']");
}
}
......@@ -54,7 +54,6 @@ protected function setupTestFields() {
'entity_type' => $this->entityTypeId,
'type' => 'image',
'cardinality' => $this->cardinality,
'translatable' => TRUE,
))->save();
entity_create('field_config', array(
......
......@@ -12,7 +12,7 @@
use Drupal\simpletest\WebTestBase;
/**
* Tests content translation workflows.
* Base class for content translation tests.
*/
abstract class ContentTranslationTestBase extends WebTestBase {
......@@ -181,7 +181,6 @@ protected function setupTestFields() {
'type' => 'string',
'entity_type' => $this->entityTypeId,
'cardinality' => 1,
'translatable' => TRUE,
))->save();
entity_create('field_config', array(
'entity_type' => $this->entityTypeId,
......@@ -208,7 +207,7 @@ protected function setupTestFields() {
* (optional) The entity bundle, if the entity uses bundles. Defaults to
* NULL. If left NULL, $this->bundle will be used.
*
* @return
* @return string
* The entity id.
*/
protected function createEntity($values, $langcode, $bundle_name = NULL) {
......
......@@ -85,7 +85,6 @@ protected function setUp() {
'entity_type' => $this->entity_type,
'type' => 'test_field',
'cardinality' => 4,
'translatable' => TRUE,
);
$this->fieldStorage = entity_create('field_storage_config', $this->field_storage_definition);
$this->fieldStorage->save();
......
......@@ -63,7 +63,6 @@ protected function setUp() {
'entity_type' => $this->entity_type,
'type' => 'test_field',
'cardinality' => 4,
'translatable' => TRUE,
);
entity_create('field_storage_config', $field_storage)->save();
$this->fieldStorage = entity_load('field_storage_config', $this->entity_type . '.' . $this->field_name);
......
......@@ -223,11 +223,13 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t
);
}
// Place the 'translatable' property as an explicit value so that
// contrib modules can form_alter() the value for newly created fields.
// Place the 'translatable' property as an explicit value so that contrib
// modules can form_alter() the value for newly created fields. By default
// we create field storage as translatable so it will be possible to enable
// translation at field level.
$form['translatable'] = array(
'#type' => 'value',
'#value' => FALSE,
'#value' => TRUE,
);
$form['actions'] = array('#type' => 'actions');
......
......@@ -58,7 +58,6 @@ protected function setUp() {
'entity_type' => 'node',
'type' => 'boolean',
'cardinality' => 1,
'translatable' => TRUE,
'settings' => array(
'on_label' => 'Private',
'off_label' => 'Not private',
......
......@@ -56,11 +56,10 @@ protected function setUp() {
'entity_type' => 'node',
'type' => 'boolean',
'cardinality' => 1,
'translatable' => TRUE,
'settings' => array(
'on_label' => 'Private',
'off_label' => 'Not private',
),
'settings' => array(
'on_label' => 'Private',
'off_label' => 'Not private',
),
));
$field_storage->save();
......
......@@ -7,7 +7,6 @@
namespace Drupal\node\Tests\Views;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\language\Entity\ConfigurableLanguage;
/**
......@@ -48,12 +47,6 @@ function setUp() {
ConfigurableLanguage::createFromLangcode('fr')->save();
ConfigurableLanguage::createFromLangcode('es')->save();
// Make the body field translatable. The title is already translatable by
// definition.
$field_storage = FieldStorageConfig::loadByName('node', 'body');
$field_storage->translatable = TRUE;
$field_storage->save();
// Set up node titles.
$this->node_titles = array(
'en' => 'Food in Paris',
......
......@@ -68,7 +68,6 @@ protected function setUp() {
'entity_type' => 'entity_test_mulrev',
'type' => $field_type,
'cardinality' => 2,
'translatable' => TRUE,
));
$field_storage->save();
$field_storages[] = $field_storage;
......
......@@ -66,7 +66,6 @@ function setUp() {
'entity_type' => 'taxonomy_term',
'type' => 'text',
));
$field->translatable = TRUE;
$field->save();
entity_create('field_config', array(
'field_name' => 'field_foo',
......
......@@ -15,7 +15,6 @@ settings:
module: image
locked: false
cardinality: 1
translatable: false
indexes:
target_id:
- target_id
......
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