Issue #2363099 by Gábor Hojtsy, Berdir, swentel, plach: Using translated field definition descriptions in entity schema results in different schema definitions, resulting in update.php changes
parent
a801764e01
commit
26b99df319
|
@ -1418,7 +1418,6 @@ class SqlContentEntityStorageSchema implements DynamicallyFieldableEntityStorage
|
|||
}
|
||||
|
||||
$field_name = $storage_definition->getName();
|
||||
$field_description = $storage_definition->getDescription();
|
||||
$base_table = $this->storage->getBaseTable();
|
||||
|
||||
// A shared table contains rows for entities where the field is empty
|
||||
|
@ -1447,7 +1446,6 @@ class SqlContentEntityStorageSchema implements DynamicallyFieldableEntityStorage
|
|||
$column_schema = $field_schema['columns'][$field_column_name];
|
||||
|
||||
$schema['fields'][$schema_field_name] = $column_schema;
|
||||
$schema['fields'][$schema_field_name]['description'] = $field_description;
|
||||
$schema['fields'][$schema_field_name]['not null'] = in_array($field_name, $not_null_keys);
|
||||
}
|
||||
|
||||
|
|
|
@ -70,6 +70,9 @@ interface DataDefinitionInterface {
|
|||
/**
|
||||
* Returns a human readable description.
|
||||
*
|
||||
* Descriptions are usually used on user interfaces where the data is edited
|
||||
* or displayed.
|
||||
*
|
||||
* @return string|null
|
||||
* The description, or NULL if no description is available.
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains Drupal\locale\Tests\LocaleTranslatedSchemaDefinitionTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\locale\Tests;
|
||||
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
/**
|
||||
* Adds and configures languages to check field schema definition.
|
||||
*
|
||||
* @group locale
|
||||
*/
|
||||
class LocaleTranslatedSchemaDefinitionTest extends WebTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('language', 'locale', 'node');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
ConfigurableLanguage::createFromLangcode('fr')->save();
|
||||
$this->config('system.site')->set('langcode', 'fr')->save();
|
||||
// Clear all caches so that the base field definition, its cache in the
|
||||
// entity manager, the t() cache, etc. are all cleared.
|
||||
drupal_flush_all_caches();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that translated field descriptions do not affect the update system.
|
||||
*/
|
||||
function testTranslatedSchemaDefinition() {
|
||||
/** @var \Drupal\locale\StringDatabaseStorage $stringStorage */
|
||||
$stringStorage = \Drupal::service('locale.storage');
|
||||
|
||||
$source = $stringStorage->createString(array(
|
||||
'source' => 'The node ID.',
|
||||
))->save();
|
||||
|
||||
$stringStorage->createTranslation(array(
|
||||
'lid' => $source->lid,
|
||||
'language' => 'fr',
|
||||
'translation' => 'Translated node ID',
|
||||
))->save();
|
||||
|
||||
// Ensure that the field is translated when access through the API.
|
||||
$this->assertEqual('Translated node ID', \Drupal::entityManager()->getBaseFieldDefinitions('node')['nid']->getDescription());
|
||||
|
||||
// Assert there are no updates.
|
||||
$this->assertFalse(\Drupal::service('entity.definition_update_manager')->needsUpdates());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that translations do not affect the update system.
|
||||
*/
|
||||
function testTranslatedUpdate() {
|
||||
// Visit the update page to collect any strings that may be translatable.
|
||||
$user = $this->drupalCreateUser(array('administer software updates'));
|
||||
$this->drupalLogin($user);
|
||||
$update_url = $GLOBALS['base_url'] . '/update.php';
|
||||
$this->drupalGet($update_url, array('external' => TRUE));
|
||||
|
||||
/** @var \Drupal\locale\StringDatabaseStorage $stringStorage */
|
||||
$stringStorage = \Drupal::service('locale.storage');
|
||||
$sources = $stringStorage->getStrings();
|
||||
|
||||
// Translate all source strings found.
|
||||
foreach ($sources as $source) {
|
||||
$stringStorage->createTranslation(array(
|
||||
'lid' => $source->lid,
|
||||
'language' => 'fr',
|
||||
'translation' => $this->randomMachineName(100),
|
||||
))->save();
|
||||
}
|
||||
|
||||
// Ensure that there are no updates just due to translations. Check for
|
||||
// markup and a link instead of specific text because text may be
|
||||
// translated.
|
||||
$this->drupalGet($update_url . '/selection', array('external' => TRUE));
|
||||
$this->assertRaw('messages--status', 'No pending updates.');
|
||||
$this->assertNoLinkByHref('fr/update.php/run', 'No link to run updates.');
|
||||
}
|
||||
}
|
|
@ -112,11 +112,9 @@ class SqlContentEntityStorageSchemaTest extends UnitTestCase {
|
|||
'columns' => array(
|
||||
'value' => array(
|
||||
'type' => 'text',
|
||||
'description' => 'The text value',
|
||||
),
|
||||
'format' => array(
|
||||
'type' => 'varchar',
|
||||
'description' => 'The text description',
|
||||
),
|
||||
),
|
||||
));
|
||||
|
@ -248,95 +246,77 @@ class SqlContentEntityStorageSchemaTest extends UnitTestCase {
|
|||
'description' => 'The base table for entity_test entities.',
|
||||
'fields' => array(
|
||||
'id' => array(
|
||||
'description' => 'The id field.',
|
||||
'type' => 'serial',
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'name' => array(
|
||||
'description' => 'The name field.',
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => FALSE,
|
||||
),
|
||||
'description__value' => array(
|
||||
'description' => 'The description field.',
|
||||
'type' => 'text',
|
||||
'not null' => FALSE,
|
||||
),
|
||||
'description__format' => array(
|
||||
'description' => 'The description field.',
|
||||
'type' => 'varchar',
|
||||
'not null' => FALSE,
|
||||
),
|
||||
'uuid' => array(
|
||||
'description' => 'The uuid field.',
|
||||
'type' => 'varchar',
|
||||
'length' => 128,
|
||||
'not null' => FALSE,
|
||||
),
|
||||
'hash' => array(
|
||||
'description' => 'The hash field.',
|
||||
'type' => 'varchar',
|
||||
'length' => 20,
|
||||
'not null' => FALSE,
|
||||
),
|
||||
'email__username' => array(
|
||||
'description' => 'The email field.',
|
||||
'type' => 'varchar',
|
||||
'not null' => FALSE,
|
||||
),
|
||||
'email__hostname' => array(
|
||||
'description' => 'The email field.',
|
||||
'type' => 'varchar',
|
||||
'not null' => FALSE,
|
||||
),
|
||||
'email__domain' => array(
|
||||
'description' => 'The email field.',
|
||||
'type' => 'varchar',
|
||||
'not null' => FALSE,
|
||||
),
|
||||
'owner' => array(
|
||||
'description' => 'The owner field.',
|
||||
'type' => 'int',
|
||||
'not null' => FALSE,
|
||||
),
|
||||
'translator' => array(
|
||||
'description' => 'The translator field.',
|
||||
'type' => 'int',
|
||||
'not null' => FALSE,
|
||||
),
|
||||
'location__country' => array(
|
||||
'description' => 'The location field.',
|
||||
'type' => 'varchar',
|
||||
'not null' => FALSE,
|
||||
),
|
||||
'location__state' => array(
|
||||
'description' => 'The location field.',
|
||||
'type' => 'varchar',
|
||||
'not null' => FALSE,
|
||||
),
|
||||
'location__city' => array(
|
||||
'description' => 'The location field.',
|
||||
'type' => 'varchar',
|
||||
'not null' => FALSE,
|
||||
),
|
||||
'editor' => array(
|
||||
'description' => 'The editor field.',
|
||||
'type' => 'int',
|
||||
'not null' => FALSE,
|
||||
),
|
||||
'editor_revision__target_id' => array(
|
||||
'description' => 'The editor_revision field.',
|
||||
'type' => 'int',
|
||||
'not null' => FALSE,
|
||||
),
|
||||
'editor_revision__target_revision_id' => array(
|
||||
'description' => 'The editor_revision field.',
|
||||
'type' => 'int',
|
||||
'not null' => FALSE,
|
||||
),
|
||||
'long_index_name' => array(
|
||||
'description' => 'The long_index_name field.',
|
||||
'type' => 'int',
|
||||
'not null' => FALSE,
|
||||
),
|
||||
|
@ -439,12 +419,10 @@ class SqlContentEntityStorageSchemaTest extends UnitTestCase {
|
|||
'description' => 'The base table for entity_test entities.',
|
||||
'fields' => array(
|
||||
'id' => array(
|
||||
'description' => 'The id field.',
|
||||
'type' => 'serial',
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'revision_id' => array(
|
||||
'description' => 'The revision_id field.',
|
||||
'type' => 'int',
|
||||
'not null' => FALSE,
|
||||
)
|
||||
|
@ -465,12 +443,10 @@ class SqlContentEntityStorageSchemaTest extends UnitTestCase {
|
|||
'description' => 'The revision table for entity_test entities.',
|
||||
'fields' => array(
|
||||
'id' => array(
|
||||
'description' => 'The id field.',
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'revision_id' => array(
|
||||
'description' => 'The revision_id field.',
|
||||
'type' => 'serial',
|
||||
'not null' => TRUE,
|
||||
),
|
||||
|
@ -538,12 +514,10 @@ class SqlContentEntityStorageSchemaTest extends UnitTestCase {
|
|||
'description' => 'The base table for entity_test entities.',
|
||||
'fields' => array(
|
||||
'id' => array(
|
||||
'description' => 'The id field.',
|
||||
'type' => 'serial',
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'langcode' => array(
|
||||
'description' => 'The langcode field.',
|
||||
'type' => 'varchar',
|
||||
'not null' => TRUE,
|
||||
)
|
||||
|
@ -557,12 +531,10 @@ class SqlContentEntityStorageSchemaTest extends UnitTestCase {
|
|||
'description' => 'The data table for entity_test entities.',
|
||||
'fields' => array(
|
||||
'id' => array(
|
||||
'description' => 'The id field.',
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'langcode' => array(
|
||||
'description' => 'The langcode field.',
|
||||
'type' => 'varchar',
|
||||
'not null' => TRUE,
|
||||
),
|
||||
|
@ -645,17 +617,14 @@ class SqlContentEntityStorageSchemaTest extends UnitTestCase {
|
|||
'description' => 'The base table for entity_test entities.',
|
||||
'fields' => array(
|
||||
'id' => array(
|
||||
'description' => 'The id field.',
|
||||
'type' => 'serial',
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'revision_id' => array(
|
||||
'description' => 'The revision_id field.',
|
||||
'type' => 'int',
|
||||
'not null' => FALSE,
|
||||
),
|
||||
'langcode' => array(
|
||||
'description' => 'The langcode field.',
|
||||
'type' => 'varchar',
|
||||
'not null' => TRUE,
|
||||
)
|
||||
|
@ -676,17 +645,14 @@ class SqlContentEntityStorageSchemaTest extends UnitTestCase {
|
|||
'description' => 'The revision table for entity_test entities.',
|
||||
'fields' => array(
|
||||
'id' => array(
|
||||
'description' => 'The id field.',
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'revision_id' => array(
|
||||
'description' => 'The revision_id field.',
|
||||
'type' => 'serial',
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'langcode' => array(
|
||||
'description' => 'The langcode field.',
|
||||
'type' => 'varchar',
|
||||
'not null' => TRUE,
|
||||
),
|
||||
|
@ -707,17 +673,14 @@ class SqlContentEntityStorageSchemaTest extends UnitTestCase {
|
|||
'description' => 'The data table for entity_test entities.',
|
||||
'fields' => array(
|
||||
'id' => array(
|
||||
'description' => 'The id field.',
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'revision_id' => array(
|
||||
'description' => 'The revision_id field.',
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'langcode' => array(
|
||||
'description' => 'The langcode field.',
|
||||
'type' => 'varchar',
|
||||
'not null' => TRUE,
|
||||
),
|
||||
|
@ -738,17 +701,14 @@ class SqlContentEntityStorageSchemaTest extends UnitTestCase {
|
|||
'description' => 'The revision data table for entity_test entities.',
|
||||
'fields' => array(
|
||||
'id' => array(
|
||||
'description' => 'The id field.',
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'revision_id' => array(
|
||||
'description' => 'The revision_id field.',
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'langcode' => array(
|
||||
'description' => 'The langcode field.',
|
||||
'type' => 'varchar',
|
||||
'not null' => TRUE,
|
||||
),
|
||||
|
@ -1242,10 +1202,6 @@ class SqlContentEntityStorageSchemaTest extends UnitTestCase {
|
|||
$this->storageDefinitions[$field_name]->expects($this->any())
|
||||
->method('getName')
|
||||
->will($this->returnValue($field_name));
|
||||
// getDescription() is called once for each table.
|
||||
$this->storageDefinitions[$field_name]->expects($this->any())
|
||||
->method('getDescription')
|
||||
->will($this->returnValue("The $field_name field."));
|
||||
// getSchema() is called once for each table.
|
||||
$this->storageDefinitions[$field_name]->expects($this->any())
|
||||
->method('getSchema')
|
||||
|
|
|
@ -324,7 +324,6 @@ class SqlContentEntityStorageTest extends UnitTestCase {
|
|||
'fields' => array(
|
||||
'id' => array(
|
||||
'type' => 'serial',
|
||||
'description' => NULL,
|
||||
'not null' => TRUE,
|
||||
),
|
||||
),
|
||||
|
|
Loading…
Reference in New Issue