summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorAlex Pott2014-12-29 22:15:19 (GMT)
committerAlex Pott2014-12-29 22:15:19 (GMT)
commitb778bfd1ecafc8cd12d8733d98e2d8cea4d8d975 (patch)
tree446512055908cc45d9a7d26ec1db73ddf061c113 /core
parent847a50ac1c7985e772ea467c89adb7150f6f35f4 (diff)
Issue #2143729 by tstoeckler, plach, jsbalsera, Berdir, mauzeh, damiankloip, andypost: Entity definitions miss a language entity key
Diffstat (limited to 'core')
-rw-r--r--core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php2
-rw-r--r--core/lib/Drupal/Core/Config/Entity/ConfigEntityType.php1
-rw-r--r--core/lib/Drupal/Core/Entity/ContentEntityBase.php54
-rw-r--r--core/lib/Drupal/Core/Entity/Entity.php3
-rw-r--r--core/lib/Drupal/Core/Entity/EntityManager.php2
-rw-r--r--core/lib/Drupal/Core/Entity/EntityStorageBase.php8
-rw-r--r--core/lib/Drupal/Core/Entity/EntityType.php3
-rw-r--r--core/lib/Drupal/Core/Entity/EntityTypeInterface.php15
-rw-r--r--core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueEntityStorage.php2
-rw-r--r--core/lib/Drupal/Core/Entity/Query/Sql/Tables.php7
-rw-r--r--core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php8
-rw-r--r--core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php10
-rw-r--r--core/modules/aggregator/src/Entity/Feed.php1
-rw-r--r--core/modules/aggregator/src/Entity/Item.php1
-rw-r--r--core/modules/block_content/src/Entity/BlockContent.php1
-rw-r--r--core/modules/comment/src/Entity/Comment.php1
-rw-r--r--core/modules/content_translation/content_translation.module2
-rw-r--r--core/modules/content_translation/src/ContentTranslationHandler.php6
-rw-r--r--core/modules/file/src/Entity/File.php12
-rw-r--r--core/modules/hal/src/Normalizer/ContentEntityNormalizer.php11
-rw-r--r--core/modules/language/language.module20
-rw-r--r--core/modules/menu_link_content/src/Entity/MenuLinkContent.php1
-rw-r--r--core/modules/node/src/Entity/Node.php1
-rw-r--r--core/modules/rest/src/Plugin/rest/resource/EntityResource.php5
-rw-r--r--core/modules/shortcut/src/Entity/Shortcut.php3
-rw-r--r--core/modules/system/src/Tests/Entity/EntityApiTest.php12
-rw-r--r--core/modules/system/src/Tests/Entity/EntityFieldDefaultValueTest.php12
-rw-r--r--core/modules/system/src/Tests/Entity/EntityFieldTest.php42
-rw-r--r--core/modules/system/src/Tests/Entity/EntityFormTest.php4
-rw-r--r--core/modules/system/src/Tests/Entity/EntityLanguageTestBase.php9
-rw-r--r--core/modules/system/src/Tests/Entity/EntityTranslationTest.php102
-rw-r--r--core/modules/system/src/Tests/Entity/EntityUUIDTest.php9
-rw-r--r--core/modules/system/src/Tests/Entity/EntityValidationTest.php7
-rw-r--r--core/modules/system/src/Tests/Installer/InstallerTranslationTest.php6
-rw-r--r--core/modules/system/tests/modules/entity_test/entity_test.install8
-rw-r--r--core/modules/system/tests/modules/entity_test/entity_test.module29
-rw-r--r--core/modules/system/tests/modules/entity_test/entity_test.routing.yml28
-rw-r--r--core/modules/system/tests/modules/entity_test/src/Entity/EntityTest.php3
-rw-r--r--core/modules/system/tests/modules/entity_test/src/Entity/EntityTestDefaultValue.php3
-rw-r--r--core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMul.php3
-rw-r--r--core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulDefaultValue.php3
-rw-r--r--core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulLangcodeKey.php58
-rw-r--r--core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulRev.php5
-rw-r--r--core/modules/system/tests/modules/entity_test/src/Entity/EntityTestRev.php1
-rw-r--r--core/modules/system/tests/modules/entity_test/src/Routing/EntityTestRoutes.php8
-rw-r--r--core/modules/taxonomy/src/Entity/Term.php1
-rw-r--r--core/modules/user/src/Entity/User.php1
-rw-r--r--core/modules/views/src/Entity/Render/TranslationLanguageRenderer.php6
-rw-r--r--core/modules/views/src/EntityViewsData.php2
-rw-r--r--core/modules/views/tests/src/Unit/EntityViewsDataTest.php2
-rw-r--r--core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php1
-rw-r--r--core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php13
-rw-r--r--core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php6
-rw-r--r--core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php5
-rw-r--r--core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php1
-rw-r--r--core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php2
-rw-r--r--core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php4
57 files changed, 384 insertions, 192 deletions
diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php
index a031ac8..ca6ed7a 100644
--- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php
+++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php
@@ -189,7 +189,7 @@ class ConfigEntityStorage extends EntityStorageBase implements ConfigEntityStora
*/
protected function doCreate(array $values) {
// Set default language to site default if not provided.
- $values += array('langcode' => $this->languageManager->getDefaultLanguage()->getId());
+ $values += array($this->langcodeKey => $this->languageManager->getDefaultLanguage()->getId());
$entity = new $this->entityClass($values, $this->entityTypeId);
return $entity;
diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityType.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityType.php
index ef46168..3fe34f1 100644
--- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityType.php
+++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityType.php
@@ -67,6 +67,7 @@ class ConfigEntityType extends EntityType {
parent::__construct($definition);
// Always add a default 'uuid' key.
$this->entity_keys['uuid'] = 'uuid';
+ $this->entity_keys['langcode'] = 'langcode';
$this->handlers += array(
'storage' => 'Drupal\Core\Config\Entity\ConfigEntityStorage',
);
diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php
index b645520..a767326 100644
--- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php
+++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php
@@ -9,6 +9,7 @@ namespace Drupal\Core\Entity;
use Drupal\Component\Utility\String;
use Drupal\Core\Entity\Plugin\DataType\EntityReference;
+use Drupal\Core\Language\Language;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\TypedData\TypedDataInterface;
@@ -74,6 +75,13 @@ abstract class ContentEntityBase extends Entity implements \IteratorAggregate, C
protected $languages;
/**
+ * The language entity key.
+ *
+ * @var string
+ */
+ protected $langcodeKey;
+
+ /**
* Language code identifying the entity active language.
*
* This is the language field accessors will use to determine which field
@@ -135,6 +143,7 @@ abstract class ContentEntityBase extends Entity implements \IteratorAggregate, C
public function __construct(array $values, $entity_type, $bundle = FALSE, $translations = array()) {
$this->entityTypeId = $entity_type;
$this->entityKeys['bundle'] = $bundle ? $bundle : $this->entityTypeId;
+ $this->langcodeKey = $this->getEntityType()->getKey('langcode');
foreach ($values as $key => $value) {
// If the key matches an existing property set the value to the property
@@ -190,6 +199,12 @@ abstract class ContentEntityBase extends Entity implements \IteratorAggregate, C
protected function getLanguages() {
if (empty($this->languages)) {
$this->languages = $this->languageManager()->getLanguages(LanguageInterface::STATE_ALL);
+ // If the entity references a language that is not or no longer available,
+ // we return a mock language object to avoid disrupting the consuming
+ // code.
+ if (!isset($this->languages[$this->defaultLangcode])) {
+ $this->languages[$this->defaultLangcode] = new Language(array('id' => $this->defaultLangcode));
+ }
}
return $this->languages;
}
@@ -485,24 +500,31 @@ abstract class ContentEntityBase extends Entity implements \IteratorAggregate, C
*/
protected function setDefaultLangcode() {
// Get the language code if the property exists.
- if ($this->hasField('langcode') && ($item = $this->get('langcode')) && isset($item->language)) {
+ // Try to read the value directly from the list of entity keys which got
+ // initialized in __construct(). This avoids creating a field item object.
+ if (isset($this->entityKeys['langcode'])) {
+ $this->defaultLangcode = $this->entityKeys['langcode'];
+ }
+ elseif ($this->hasField($this->langcodeKey) && ($item = $this->get($this->langcodeKey)) && isset($item->language)) {
$this->defaultLangcode = $item->language->getId();
+ $this->entityKeys['langcode'] = $this->defaultLangcode;
}
if (empty($this->defaultLangcode)) {
// Make sure we return a proper language object, if the entity has a
// langcode field, default to the site's default language.
- if ($this->hasField('langcode')) {
+ if ($this->hasField($this->langcodeKey)) {
$this->defaultLangcode = $this->languageManager()->getDefaultLanguage()->getId();
}
else {
$this->defaultLangcode = LanguageInterface::LANGCODE_NOT_SPECIFIED;
}
}
+
// This needs to be initialized manually as it is skipped when instantiating
// the language field object to avoid infinite recursion.
- if (!empty($this->fields['langcode'])) {
- $this->fields['langcode'][LanguageInterface::LANGCODE_DEFAULT]->setLangcode($this->defaultLangcode);
+ if (!empty($this->fields[$this->langcodeKey])) {
+ $this->fields[$this->langcodeKey][LanguageInterface::LANGCODE_DEFAULT]->setLangcode($this->defaultLangcode);
}
}
@@ -521,14 +543,6 @@ abstract class ContentEntityBase extends Entity implements \IteratorAggregate, C
* {@inheritdoc}
*/
public function onChange($name) {
- if ($name == 'langcode') {
- $this->setDefaultLangcode();
- if (isset($this->translations[$this->defaultLangcode])) {
- $message = String::format('A translation already exists for the specified language (@langcode).', array('@langcode' => $this->defaultLangcode));
- throw new \InvalidArgumentException($message);
- }
- $this->updateFieldLangcodes($this->defaultLangcode);
- }
// Check if the changed name is the value of an entity key and if the value
// of that is currently cached, if so, reset it. Exclude the bundle from
// that check, as it ready only and must not change, unsetting it could
@@ -538,6 +552,16 @@ abstract class ContentEntityBase extends Entity implements \IteratorAggregate, C
unset($this->entityKeys[$key]);
}
}
+
+ // Update the default internal language cache.
+ if ($name == $this->langcodeKey) {
+ $this->setDefaultLangcode();
+ if (isset($this->translations[$this->defaultLangcode])) {
+ $message = String::format('A translation already exists for the specified language (@langcode).', array('@langcode' => $this->defaultLangcode));
+ throw new \InvalidArgumentException($message);
+ }
+ $this->updateFieldLangcodes($this->defaultLangcode);
+ }
}
/**
@@ -656,7 +680,11 @@ abstract class ContentEntityBase extends Entity implements \IteratorAggregate, C
// Instantiate a new empty entity so default values will be populated in the
// specified language.
$entity_type = $this->getEntityType();
- $default_values = array($entity_type->getKey('bundle') => $this->bundle(), 'langcode' => $langcode);
+
+ $default_values = array(
+ $entity_type->getKey('bundle') => $this->bundle(),
+ $this->langcodeKey => $langcode,
+ );
$entity = $this->entityManager()
->getStorage($this->getEntityTypeId())
->create($default_values);
diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php
index a867053..c76dc40 100644
--- a/core/lib/Drupal/Core/Entity/Entity.php
+++ b/core/lib/Drupal/Core/Entity/Entity.php
@@ -309,7 +309,8 @@ abstract class Entity implements EntityInterface {
* {@inheritdoc}
*/
public function language() {
- $language = $this->languageManager()->getLanguage($this->langcode);
+ $langcode = $this->{$this->getEntityType()->getKey('langcode')};
+ $language = $this->languageManager()->getLanguage($langcode);
if (!$language) {
// Make sure we return a proper language object.
$langcode = $this->langcode ?: LanguageInterface::LANGCODE_NOT_SPECIFIED;
diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php
index 7d7eded..df404d8 100644
--- a/core/lib/Drupal/Core/Entity/EntityManager.php
+++ b/core/lib/Drupal/Core/Entity/EntityManager.php
@@ -434,7 +434,7 @@ class EntityManager extends DefaultPluginManager implements EntityManagerInterfa
// Ensure defined entity keys are there and have proper revisionable and
// translatable values.
- $keys = array_filter($entity_type->getKeys() + array('langcode' => 'langcode'));
+ $keys = array_filter($entity_type->getKeys());
foreach ($keys as $key => $field_name) {
if (isset($base_field_definitions[$field_name]) && in_array($key, array('id', 'revision', 'uuid', 'bundle')) && $base_field_definitions[$field_name]->isRevisionable()) {
throw new \LogicException(String::format('The @field field cannot be revisionable as it is used as @key entity key.', array('@field' => $base_field_definitions[$field_name]->getLabel(), '@key' => $key)));
diff --git a/core/lib/Drupal/Core/Entity/EntityStorageBase.php b/core/lib/Drupal/Core/Entity/EntityStorageBase.php
index d4daa67..7a43b75 100644
--- a/core/lib/Drupal/Core/Entity/EntityStorageBase.php
+++ b/core/lib/Drupal/Core/Entity/EntityStorageBase.php
@@ -58,6 +58,13 @@ abstract class EntityStorageBase extends EntityHandlerBase implements EntityStor
protected $uuidKey;
/**
+ * The name of the entity langcode property.
+ *
+ * @var string
+ */
+ protected $langcodeKey;
+
+ /**
* The UUID service.
*
* @var \Drupal\Component\Uuid\UuidInterface
@@ -82,6 +89,7 @@ abstract class EntityStorageBase extends EntityHandlerBase implements EntityStor
$this->entityType = $entity_type;
$this->idKey = $this->entityType->getKey('id');
$this->uuidKey = $this->entityType->getKey('uuid');
+ $this->langcodeKey = $this->entityType->getKey('langcode');
$this->entityClass = $this->entityType->getClass();
}
diff --git a/core/lib/Drupal/Core/Entity/EntityType.php b/core/lib/Drupal/Core/Entity/EntityType.php
index faf8856..c5d90ca 100644
--- a/core/lib/Drupal/Core/Entity/EntityType.php
+++ b/core/lib/Drupal/Core/Entity/EntityType.php
@@ -236,7 +236,8 @@ class EntityType implements EntityTypeInterface {
// Ensure defaults.
$this->entity_keys += array(
'revision' => '',
- 'bundle' => ''
+ 'bundle' => '',
+ 'langcode' => '',
);
$this->handlers += array(
'access' => 'Drupal\Core\Entity\EntityAccessControlHandler',
diff --git a/core/lib/Drupal/Core/Entity/EntityTypeInterface.php b/core/lib/Drupal/Core/Entity/EntityTypeInterface.php
index ec61644..e2ba2a9 100644
--- a/core/lib/Drupal/Core/Entity/EntityTypeInterface.php
+++ b/core/lib/Drupal/Core/Entity/EntityTypeInterface.php
@@ -105,12 +105,15 @@ interface EntityTypeInterface {
* entry can be omitted if this entity type exposes a single bundle (such
* that all entities have the same collection of fields). The name of this
* single bundle will be the same as the entity type.
- * - label: The name of the property that contains the entity label. For
- * example, if the entity's label is located in $entity->subject, then
- * 'subject' should be specified here. If complex logic is required to
- * build the label, a 'label_callback' should be defined instead (see the
- * $label_callback block above for details).
- * - uuid (optional): The name of the property that contains the universally
+ * - label: (optional) The name of the property that contains the entity
+ * label. For example, if the entity's label is located in
+ * $entity->subject, then 'subject' should be specified here. If complex
+ * logic is required to build the label, a 'label_callback' should be
+ * defined instead (see the $label_callback block above for details).
+ * - langcode: (optional) The name of the property that contains the
+ * language code. For instance, if the entity's language is located in
+ * $entity->langcode, then 'langcode' should be specified here.
+ * - uuid: (optional) The name of the property that contains the universally
* unique identifier of the entity, which is used to distinctly identify
* an entity across different systems.
*/
diff --git a/core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueEntityStorage.php b/core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueEntityStorage.php
index 3507502..365020c 100644
--- a/core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueEntityStorage.php
+++ b/core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueEntityStorage.php
@@ -94,7 +94,7 @@ class KeyValueEntityStorage extends EntityStorageBase {
*/
public function doCreate(array $values = array()) {
// Set default language to site default if not provided.
- $values += array('langcode' => $this->languageManager->getDefaultLanguage()->getId());
+ $values += array($this->getEntityType()->getKey('langcode') => $this->languageManager->getDefaultLanguage()->getId());
$entity = new $this->entityClass($values, $this->entityTypeId);
// @todo This is handled by ContentEntityStorageBase, which assumes
diff --git a/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php b/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php
index ffd84d4..65885e0 100644
--- a/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php
+++ b/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php
@@ -262,8 +262,13 @@ class Tables implements TablesInterface {
protected function addJoin($type, $table, $join_condition, $langcode) {
$arguments = array();
if ($langcode) {
+ $entity_type_id = $this->sqlQuery->getMetaData('entity_type');
+ $entity_type = $this->entityManager->getDefinition($entity_type_id);
+ // Only the data table follows the entity language key, dedicated field
+ // tables have an hard-coded 'langcode' column.
+ $langcode_key = $entity_type->getDataTable() == $table ? $entity_type->getKey('langcode') : 'langcode';
$placeholder = ':langcode' . $this->sqlQuery->nextPlaceholder();
- $join_condition .= ' AND %alias.langcode = ' . $placeholder;
+ $join_condition .= ' AND %alias.' . $langcode_key . ' = ' . $placeholder;
$arguments[$placeholder] = $langcode;
}
return $this->sqlQuery->addJoin($type, $table, NULL, $join_condition, $arguments);
diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php
index 40a695e..e531d09 100644
--- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php
+++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php
@@ -186,7 +186,7 @@ class SqlContentEntityStorage extends ContentEntityStorageBase implements SqlEnt
$translatable = $this->entityType->isTranslatable();
if ($translatable) {
$this->dataTable = $this->entityType->getDataTable() ?: $this->entityTypeId . '_field_data';
- $this->langcodeKey = $this->entityType->getKey('langcode') ?: 'langcode';
+ $this->langcodeKey = $this->entityType->getKey('langcode');
$this->defaultLangcodeKey = $this->entityType->getKey('default_langcode') ?: 'default_langcode';
}
if ($revisionable && $translatable) {
@@ -682,7 +682,7 @@ class SqlContentEntityStorage extends ContentEntityStorageBase implements SqlEnt
// Field values in default language are stored with
// LanguageInterface::LANGCODE_DEFAULT as key.
- $langcode = empty($values['default_langcode']) ? $values['langcode'] : LanguageInterface::LANGCODE_DEFAULT;
+ $langcode = empty($values['default_langcode']) ? $values[$this->langcodeKey] : LanguageInterface::LANGCODE_DEFAULT;
$translations[$id][$langcode] = TRUE;
@@ -1145,8 +1145,8 @@ class SqlContentEntityStorage extends ContentEntityStorageBase implements SqlEnt
$table_name = $this->dataTable;
}
$record = $this->mapToStorageRecord($entity, $table_name);
- $record->langcode = $entity->language()->getId();
- $record->default_langcode = intval($record->langcode == $entity->getUntranslated()->language()->getId());
+ $record->{$this->langcodeKey} = $entity->language()->getId();
+ $record->default_langcode = intval($record->{$this->langcodeKey} == $entity->getUntranslated()->language()->getId());
return $record;
}
diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php
index d3087b7..c5d5853 100644
--- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php
+++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php
@@ -879,9 +879,7 @@ class SqlContentEntityStorageSchema implements DynamicallyFieldableEntityStorage
$schema = array(
'description' => "The data table for $entity_type_id entities.",
- // @todo Use the language entity key when https://drupal.org/node/2143729
- // is in.
- 'primary key' => array($id_key, 'langcode'),
+ 'primary key' => array($id_key, $entity_type->getKey('langcode')),
'indexes' => array(),
'foreign keys' => array(
$entity_type_id => array(
@@ -917,9 +915,7 @@ class SqlContentEntityStorageSchema implements DynamicallyFieldableEntityStorage
$schema = array(
'description' => "The revision data table for $entity_type_id entities.",
- // @todo Use the language entity key when https://drupal.org/node/2143729
- // is in.
- 'primary key' => array($revision_key, 'langcode'),
+ 'primary key' => array($revision_key, $entity_type->getKey('langcode')),
'indexes' => array(),
'foreign keys' => array(
$entity_type_id => array(
@@ -1397,7 +1393,7 @@ class SqlContentEntityStorageSchema implements DynamicallyFieldableEntityStorage
$schema['fields'][$schema_field_name] = $column_schema;
$schema['fields'][$schema_field_name]['description'] = $field_description;
// Only entity keys are required.
- $keys = $this->entityType->getKeys() + array('langcode' => 'langcode');
+ $keys = $this->entityType->getKeys();
// The label is an entity key, but label fields are not necessarily
// required.
// Because entity ID and revision ID are both serial fields in the base
diff --git a/core/modules/aggregator/src/Entity/Feed.php b/core/modules/aggregator/src/Entity/Feed.php
index bb03b83..fe468b6 100644
--- a/core/modules/aggregator/src/Entity/Feed.php
+++ b/core/modules/aggregator/src/Entity/Feed.php
@@ -43,6 +43,7 @@ use Drupal\aggregator\FeedInterface;
* entity_keys = {
* "id" = "fid",
* "label" = "title",
+ * "langcode" = "langcode",
* "uuid" = "uuid",
* }
* )
diff --git a/core/modules/aggregator/src/Entity/Item.php b/core/modules/aggregator/src/Entity/Item.php
index 066b7ff..21a0dca 100644
--- a/core/modules/aggregator/src/Entity/Item.php
+++ b/core/modules/aggregator/src/Entity/Item.php
@@ -35,6 +35,7 @@ use Drupal\Core\Url;
* entity_keys = {
* "id" = "iid",
* "label" = "title",
+ * "langcode" = "langcode",
* }
* )
*/
diff --git a/core/modules/block_content/src/Entity/BlockContent.php b/core/modules/block_content/src/Entity/BlockContent.php
index 6b5736e..4908d95 100644
--- a/core/modules/block_content/src/Entity/BlockContent.php
+++ b/core/modules/block_content/src/Entity/BlockContent.php
@@ -49,6 +49,7 @@ use Drupal\block_content\BlockContentInterface;
* "revision" = "revision_id",
* "bundle" = "type",
* "label" = "info",
+ * "langcode" = "langcode",
* "uuid" = "uuid"
* },
* bundle_entity_type = "block_content_type",
diff --git a/core/modules/comment/src/Entity/Comment.php b/core/modules/comment/src/Entity/Comment.php
index 07ecd36..828c1b6 100644
--- a/core/modules/comment/src/Entity/Comment.php
+++ b/core/modules/comment/src/Entity/Comment.php
@@ -43,6 +43,7 @@ use Drupal\user\UserInterface;
* "id" = "cid",
* "bundle" = "comment_type",
* "label" = "subject",
+ * "langcode" = "langcode",
* "uuid" = "uuid"
* },
* links = {
diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module
index 466b848..7ca20d4 100644
--- a/core/modules/content_translation/content_translation.module
+++ b/core/modules/content_translation/content_translation.module
@@ -291,7 +291,7 @@ function content_translation_form_alter(array &$form, FormStateInterface $form_s
// Handle fields shared between translations when there is at least one
// translation available or a new one is being created.
if (!$entity->isNew() && (!isset($translations[$form_langcode]) || count($translations) > 1)) {
- $langcode_key = $entity->getEntityType()->getKey('langcode') ?: 'langcode';
+ $langcode_key = $entity->getEntityType()->getKey('langcode');
foreach ($entity->getFieldDefinitions() as $field_name => $definition) {
if (isset($form[$field_name]) && $field_name != $langcode_key) {
$form[$field_name]['#multilingual'] = $definition->isTranslatable();
diff --git a/core/modules/content_translation/src/ContentTranslationHandler.php b/core/modules/content_translation/src/ContentTranslationHandler.php
index 4b87496..88f57ae 100644
--- a/core/modules/content_translation/src/ContentTranslationHandler.php
+++ b/core/modules/content_translation/src/ContentTranslationHandler.php
@@ -145,9 +145,9 @@ class ContentTranslationHandler implements ContentTranslationHandlerInterface {
}
// Locate the language widget.
- $language_field = $this->entityType->getKey('langcode') ?: 'langcode';
- if (isset($form[$language_field])) {
- $language_widget = &$form[$language_field];
+ $langcode_key = $this->entityType->getKey('langcode');
+ if (isset($form[$langcode_key])) {
+ $language_widget = &$form[$langcode_key];
}
// If we are editing the source entity, limit the list of languages so that
diff --git a/core/modules/file/src/Entity/File.php b/core/modules/file/src/Entity/File.php
index d1ae4f6..ea3128f 100644
--- a/core/modules/file/src/Entity/File.php
+++ b/core/modules/file/src/Entity/File.php
@@ -32,6 +32,7 @@ use Drupal\user\UserInterface;
* entity_keys = {
* "id" = "fid",
* "label" = "filename",
+ * "langcode" = "langcode",
* "uuid" = "uuid"
* }
* )
@@ -39,17 +40,6 @@ use Drupal\user\UserInterface;
class File extends ContentEntityBase implements FileInterface {
/**
- * The plain data values of the contained properties.
- *
- * Define default values.
- *
- * @var array
- */
- protected $values = array(
- 'langcode' => array(LanguageInterface::LANGCODE_DEFAULT => array(0 => array('value' => LanguageInterface::LANGCODE_NOT_SPECIFIED))),
- );
-
- /**
* {@inheritdoc}
*/
public function getFilename() {
diff --git a/core/modules/hal/src/Normalizer/ContentEntityNormalizer.php b/core/modules/hal/src/Normalizer/ContentEntityNormalizer.php
index 4a453b0..61ea214 100644
--- a/core/modules/hal/src/Normalizer/ContentEntityNormalizer.php
+++ b/core/modules/hal/src/Normalizer/ContentEntityNormalizer.php
@@ -133,16 +133,17 @@ class ContentEntityNormalizer extends NormalizerBase {
// Create the entity.
$typed_data_ids = $this->getTypedDataIds($data['_links']['type']);
+ $entity_type = $this->entityManager->getDefinition($typed_data_ids['entity_type']);
+ $langcode_key = $entity_type->getKey('langcode');
$values = array();
+
// Figure out the language to use.
- if (isset($data['langcode'])) {
- $values['langcode'] = $data['langcode'][0]['value'];
+ if (isset($data[$langcode_key])) {
+ $values[$langcode_key] = $data[$langcode_key][0]['value'];
// Remove the langcode so it does not get iterated over below.
- unset($data['langcode']);
+ unset($data[$langcode_key]);
}
- $entity_type = $this->entityManager->getDefinition($typed_data_ids['entity_type']);
-
if ($entity_type->hasKey('bundle')) {
$bundle_key = $entity_type->getKey('bundle');
$values[$bundle_key] = $typed_data_ids['bundle'];
diff --git a/core/modules/language/language.module b/core/modules/language/language.module
index de2dee5..a21682b 100644
--- a/core/modules/language/language.module
+++ b/core/modules/language/language.module
@@ -483,18 +483,18 @@ function language_form_system_regional_settings_alter(&$form, FormStateInterface
/**
* Implements hook_form_alter().
*/
-function language_form_alter(&$form, FormStateInterface $form_state, $form_id) {
+function language_form_alter(&$form, FormStateInterface $form_state) {
// Content entity forms may have added a langcode field. But content language
// configuration should decide if it should be exposed or not in the forms.
$form_object = $form_state->getFormObject();
- if ($form_object instanceof ContentEntityFormInterface && isset($form['langcode'])) {
+ if ($form_object instanceof ContentEntityFormInterface) {
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
- $entity_type_id = $form_object->getEntity()->getEntityTypeId();
- $bundle = $form_object->getEntity()->bundle();
- $entity_type = Drupal::entityManager()->getDefinition($entity_type_id);
- if ($entity_type->isTranslatable()) {
- $language_configuration = ContentLanguageSettings::loadByEntityTypeBundle($entity_type_id, $bundle);
- $form['langcode']['#access'] = $language_configuration->isLanguageAlterable();
+ $entity = $form_object->getEntity();
+ $entity_type = $entity->getEntityType();
+ $langcode_key = $entity_type->getKey('langcode');
+ if (isset($form[$langcode_key]) && $entity_type->isTranslatable()) {
+ $language_configuration = ContentLanguageSettings::loadByEntityTypeBundle($entity->getEntityTypeId(), $entity->bundle());
+ $form[$langcode_key]['#access'] = $language_configuration->isLanguageAlterable();
}
}
}
@@ -520,11 +520,11 @@ function language_field_info_alter(&$info) {
* Implements hook_entity_field_access()
*/
function language_entity_field_access($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL) {
- if ($field_definition->getName() == 'langcode') {
+ $langcode_key = $items->getEntity()->getEntityType()->getKey('langcode');
+ if ($field_definition->getName() == $langcode_key) {
$entity = $items->getEntity();
$config = ContentLanguageSettings::loadByEntityTypeBundle($entity->getEntityTypeId(), $entity->bundle());
return AccessResult::forbiddenIf(!$config->isLanguageAlterable());
}
return AccessResult::neutral();
}
-
diff --git a/core/modules/menu_link_content/src/Entity/MenuLinkContent.php b/core/modules/menu_link_content/src/Entity/MenuLinkContent.php
index c5013bd..23ef1c4 100644
--- a/core/modules/menu_link_content/src/Entity/MenuLinkContent.php
+++ b/core/modules/menu_link_content/src/Entity/MenuLinkContent.php
@@ -35,6 +35,7 @@ use Drupal\menu_link_content\MenuLinkContentInterface;
* entity_keys = {
* "id" = "id",
* "label" = "title",
+ * "langcode" = "langcode",
* "uuid" = "uuid",
* "bundle" = "bundle"
* },
diff --git a/core/modules/node/src/Entity/Node.php b/core/modules/node/src/Entity/Node.php
index e0dfbdf..4a6d74b 100644
--- a/core/modules/node/src/Entity/Node.php
+++ b/core/modules/node/src/Entity/Node.php
@@ -47,6 +47,7 @@ use Drupal\user\UserInterface;
* "revision" = "vid",
* "bundle" = "type",
* "label" = "title",
+ * "langcode" = "langcode",
* "uuid" = "uuid"
* },
* bundle_entity_type = "node_type",
diff --git a/core/modules/rest/src/Plugin/rest/resource/EntityResource.php b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php
index c861239..b7d0264 100644
--- a/core/modules/rest/src/Plugin/rest/resource/EntityResource.php
+++ b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php
@@ -134,13 +134,12 @@ class EntityResource extends ResourceBase {
}
// Overwrite the received properties.
+ $langcode_key = $entity->getEntityType()->getKey('langcode');
foreach ($entity->_restPatchFields as $field_name) {
$field = $entity->get($field_name);
// It is not possible to set the language to NULL as it is automatically
// re-initialized. As it must not be empty, skip it if it is.
- // @todo: Use the langcode entity key when available. See
- // https://drupal.org/node/2143729.
- if ($field_name == 'langcode' && $field->isEmpty()) {
+ if ($field_name == $langcode_key && $field->isEmpty()) {
continue;
}
if ($field->isEmpty() && !$original_entity->get($field_name)->access('delete')) {
diff --git a/core/modules/shortcut/src/Entity/Shortcut.php b/core/modules/shortcut/src/Entity/Shortcut.php
index 6f027f1..ad43339 100644
--- a/core/modules/shortcut/src/Entity/Shortcut.php
+++ b/core/modules/shortcut/src/Entity/Shortcut.php
@@ -39,7 +39,8 @@ use Symfony\Component\HttpFoundation\Request;
* "id" = "id",
* "uuid" = "uuid",
* "bundle" = "shortcut_set",
- * "label" = "title"
+ * "label" = "title",
+ * "langcode" = "langcode",
* },
* links = {
* "canonical" = "entity.shortcut.canonical",
diff --git a/core/modules/system/src/Tests/Entity/EntityApiTest.php b/core/modules/system/src/Tests/Entity/EntityApiTest.php
index f30e94d..decbcd0 100644
--- a/core/modules/system/src/Tests/Entity/EntityApiTest.php
+++ b/core/modules/system/src/Tests/Entity/EntityApiTest.php
@@ -17,12 +17,18 @@ use Drupal\user\UserInterface;
*/
class EntityApiTest extends EntityUnitTestBase {
+ /**
+ * @inheritdoc
+ */
protected function setUp() {
parent::setUp();
- $this->installEntitySchema('entity_test_rev');
- $this->installEntitySchema('entity_test_mul');
- $this->installEntitySchema('entity_test_mulrev');
+ foreach (entity_test_entity_types() as $entity_type_id) {
+ // The entity_test schema is installed by the parent.
+ if ($entity_type_id != 'entity_test') {
+ $this->installEntitySchema($entity_type_id);
+ }
+ }
}
/**
diff --git a/core/modules/system/src/Tests/Entity/EntityFieldDefaultValueTest.php b/core/modules/system/src/Tests/Entity/EntityFieldDefaultValueTest.php
index d315cb9..ecc5578 100644
--- a/core/modules/system/src/Tests/Entity/EntityFieldDefaultValueTest.php
+++ b/core/modules/system/src/Tests/Entity/EntityFieldDefaultValueTest.php
@@ -44,13 +44,15 @@ class EntityFieldDefaultValueTest extends EntityUnitTestBase {
/**
* Executes a test set for a defined entity type.
*
- * @param string $entity_type
+ * @param string $entity_type_id
* The entity type to run the tests with.
*/
- protected function assertDefaultValues($entity_type) {
- $entity = entity_create($entity_type);
- $this->assertEqual($entity->langcode->value, 'en', String::format('%entity_type: Default language', array('%entity_type' => $entity_type)));
- $this->assertTrue(Uuid::isValid($entity->uuid->value), String::format('%entity_type: Default UUID', array('%entity_type' => $entity_type)));
+ protected function assertDefaultValues($entity_type_id) {
+ $entity = entity_create($entity_type_id);
+ $definition = $this->entityManager->getDefinition($entity_type_id);
+ $langcode_key = $definition->getKey('langcode');
+ $this->assertEqual($entity->{$langcode_key}->value, 'en', String::format('%entity_type: Default language', array('%entity_type' => $entity_type_id)));
+ $this->assertTrue(Uuid::isValid($entity->uuid->value), String::format('%entity_type: Default UUID', array('%entity_type' => $entity_type_id)));
$this->assertEqual($entity->name->getValue(), array(0 => array('value' => NULL)), 'Field has one empty value by default.');
}
diff --git a/core/modules/system/src/Tests/Entity/EntityFieldTest.php b/core/modules/system/src/Tests/Entity/EntityFieldTest.php
index 970881d..fdc66e6 100644
--- a/core/modules/system/src/Tests/Entity/EntityFieldTest.php
+++ b/core/modules/system/src/Tests/Entity/EntityFieldTest.php
@@ -50,9 +50,12 @@ class EntityFieldTest extends EntityUnitTestBase {
protected function setUp() {
parent::setUp();
- $this->installEntitySchema('entity_test_rev');
- $this->installEntitySchema('entity_test_mul');
- $this->installEntitySchema('entity_test_mulrev');
+ foreach (entity_test_entity_types() as $entity_type_id) {
+ // The entity_test schema is installed by the parent.
+ if ($entity_type_id != 'entity_test') {
+ $this->installEntitySchema($entity_type_id);
+ }
+ }
// Create the test field.
entity_test_install();
@@ -154,7 +157,7 @@ class EntityFieldTest extends EntityUnitTestBase {
$this->assertEqual($new_user2->id(), $entity->user_id->target_id, format_string('%entity_type: Updated user id can be read.', array('%entity_type' => $entity_type)));
$this->assertEqual($new_user2->getUsername(), $entity->user_id->entity->name->value, format_string('%entity_type: Updated user name value can be read.', array('%entity_type' => $entity_type)));
- // Change the assigned user by id.
+ // Change the assigned user by id.
$entity->user_id->first()->get('target_id')->setValue($new_user2->id());
$this->assertEqual($new_user2->id(), $entity->user_id->target_id, format_string('%entity_type: Updated user id can be read.', array('%entity_type' => $entity_type)));
$this->assertEqual($new_user2->getUsername(), $entity->user_id->entity->name->value, format_string('%entity_type: Updated user name value can be read.', array('%entity_type' => $entity_type)));
@@ -222,19 +225,20 @@ class EntityFieldTest extends EntityUnitTestBase {
}
// Access the language field.
- $this->assertEqual($langcode, $entity->langcode->value, format_string('%entity_type: Language code can be read.', array('%entity_type' => $entity_type)));
- $this->assertEqual(\Drupal::languageManager()->getLanguage($langcode), $entity->langcode->language, format_string('%entity_type: Language object can be read.', array('%entity_type' => $entity_type)));
+ $langcode_key = $this->entityManager->getDefinition($entity_type)->getKey('langcode');
+ $this->assertEqual($langcode, $entity->{$langcode_key}->value, format_string('%entity_type: Language code can be read.', array('%entity_type' => $entity_type)));
+ $this->assertEqual(\Drupal::languageManager()->getLanguage($langcode), $entity->{$langcode_key}->language, format_string('%entity_type: Language object can be read.', array('%entity_type' => $entity_type)));
// Change the language by code.
- $entity->langcode->value = \Drupal::languageManager()->getDefaultLanguage()->getId();
- $this->assertEqual(\Drupal::languageManager()->getDefaultLanguage()->getId(), $entity->langcode->value, format_string('%entity_type: Language code can be read.', array('%entity_type' => $entity_type)));
- $this->assertEqual(\Drupal::languageManager()->getDefaultLanguage(), $entity->langcode->language, format_string('%entity_type: Language object can be read.', array('%entity_type' => $entity_type)));
+ $entity->{$langcode_key}->value = \Drupal::languageManager()->getDefaultLanguage()->getId();
+ $this->assertEqual(\Drupal::languageManager()->getDefaultLanguage()->getId(), $entity->{$langcode_key}->value, format_string('%entity_type: Language code can be read.', array('%entity_type' => $entity_type)));
+ $this->assertEqual(\Drupal::languageManager()->getDefaultLanguage(), $entity->{$langcode_key}->language, format_string('%entity_type: Language object can be read.', array('%entity_type' => $entity_type)));
// Revert language by code then try setting it by language object.
- $entity->langcode->value = $langcode;
- $entity->langcode->language = \Drupal::languageManager()->getDefaultLanguage();
- $this->assertEqual(\Drupal::languageManager()->getDefaultLanguage()->getId(), $entity->langcode->value, format_string('%entity_type: Language code can be read.', array('%entity_type' => $entity_type)));
- $this->assertEqual(\Drupal::languageManager()->getDefaultLanguage(), $entity->langcode->language, format_string('%entity_type: Language object can be read.', array('%entity_type' => $entity_type)));
+ $entity->{$langcode_key}->value = $langcode;
+ $entity->{$langcode_key}->language = \Drupal::languageManager()->getDefaultLanguage();
+ $this->assertEqual(\Drupal::languageManager()->getDefaultLanguage()->getId(), $entity->{$langcode_key}->value, format_string('%entity_type: Language code can be read.', array('%entity_type' => $entity_type)));
+ $this->assertEqual(\Drupal::languageManager()->getDefaultLanguage(), $entity->{$langcode_key}->language, format_string('%entity_type: Language object can be read.', array('%entity_type' => $entity_type)));
// Access the text field and test updating.
$this->assertEqual($entity->field_test_text->value, $this->entity_field_text, format_string('%entity_type: Text field can be read.', array('%entity_type' => $entity_type)));
@@ -347,6 +351,7 @@ class EntityFieldTest extends EntityUnitTestBase {
* The entity type to run the tests with.
*/
protected function doTestSave($entity_type) {
+ $langcode_key = $this->entityManager->getDefinition($entity_type)->getKey('langcode');
$entity = $this->createTestEntity($entity_type);
$entity->save();
$this->assertTrue((bool) $entity->id(), format_string('%entity_type: Entity has received an id.', array('%entity_type' => $entity_type)));
@@ -357,8 +362,8 @@ class EntityFieldTest extends EntityUnitTestBase {
// Access the name field.
$this->assertEqual(1, $entity->id->value, format_string('%entity_type: ID value can be read.', array('%entity_type' => $entity_type)));
$this->assertTrue(is_string($entity->uuid->value), format_string('%entity_type: UUID value can be read.', array('%entity_type' => $entity_type)));
- $this->assertEqual('en', $entity->langcode->value, format_string('%entity_type: Language code can be read.', array('%entity_type' => $entity_type)));
- $this->assertEqual(\Drupal::languageManager()->getLanguage('en'), $entity->langcode->language, format_string('%entity_type: Language object can be read.', array('%entity_type' => $entity_type)));
+ $this->assertEqual('en', $entity->{$langcode_key}->value, format_string('%entity_type: Language code can be read.', array('%entity_type' => $entity_type)));
+ $this->assertEqual(\Drupal::languageManager()->getLanguage('en'), $entity->{$langcode_key}->language, format_string('%entity_type: Language object can be read.', array('%entity_type' => $entity_type)));
$this->assertEqual($this->entity_user->id(), $entity->user_id->target_id, format_string('%entity_type: User id can be read.', array('%entity_type' => $entity_type)));
$this->assertEqual($this->entity_user->getUsername(), $entity->user_id->entity->name->value, format_string('%entity_type: User name can be read.', array('%entity_type' => $entity_type)));
$this->assertEqual($this->entity_field_text, $entity->field_test_text->value, format_string('%entity_type: Text field can be read.', array('%entity_type' => $entity_type)));
@@ -399,7 +404,8 @@ class EntityFieldTest extends EntityUnitTestBase {
// Test deriving metadata from references.
$entity_definition = \Drupal\Core\Entity\TypedData\EntityDataDefinition::create($entity_type);
- $reference_definition = $entity_definition->getPropertyDefinition('langcode')
+ $langcode_key = $this->entityManager->getDefinition($entity_type)->getKey('langcode');
+ $reference_definition = $entity_definition->getPropertyDefinition($langcode_key)
->getPropertyDefinition('language')
->getTargetDefinition();
$this->assertEqual($reference_definition->getDataType(), 'language');
@@ -541,7 +547,9 @@ class EntityFieldTest extends EntityUnitTestBase {
// Field format.
NULL,
);
- $this->assertEqual($strings, $target_strings, format_string('%entity_type: All contained strings found.', array('%entity_type' => $entity_type)));
+ asort($strings);
+ asort($target_strings);
+ $this->assertEqual(array_values($strings), array_values($target_strings), format_string('%entity_type: All contained strings found.', array('%entity_type' => $entity_type)));
}
/**
diff --git a/core/modules/system/src/Tests/Entity/EntityFormTest.php b/core/modules/system/src/Tests/Entity/EntityFormTest.php
index e7b21c6..ce12dfe 100644
--- a/core/modules/system/src/Tests/Entity/EntityFormTest.php
+++ b/core/modules/system/src/Tests/Entity/EntityFormTest.php
@@ -35,7 +35,7 @@ class EntityFormTest extends WebTestBase {
function testFormCRUD() {
// All entity variations have to have the same results.
foreach (entity_test_entity_types() as $entity_type) {
- $this->assertFormCRUD($entity_type);
+ $this->doTestFormCRUD($entity_type);
}
}
@@ -56,7 +56,7 @@ class EntityFormTest extends WebTestBase {
* @param string $entity_type
* The entity type to run the tests with.
*/
- protected function assertFormCRUD($entity_type) {
+ protected function doTestFormCRUD($entity_type) {
$name1 = $this->randomMachineName(8);
$name2 = $this->randomMachineName(10);
diff --git a/core/modules/system/src/Tests/Entity/EntityLanguageTestBase.php b/core/modules/system/src/Tests/Entity/EntityLanguageTestBase.php
index 6aa3c91..d453b92 100644
--- a/core/modules/system/src/Tests/Entity/EntityLanguageTestBase.php
+++ b/core/modules/system/src/Tests/Entity/EntityLanguageTestBase.php
@@ -51,9 +51,12 @@ abstract class EntityLanguageTestBase extends EntityUnitTestBase {
$this->languageManager = $this->container->get('language_manager');
- $this->installEntitySchema('entity_test_rev');
- $this->installEntitySchema('entity_test_mul');
- $this->installEntitySchema('entity_test_mulrev');
+ foreach (entity_test_entity_types() as $entity_type_id) {
+ // The entity_test schema is installed by the parent.
+ if ($entity_type_id != 'entity_test') {
+ $this->installEntitySchema($entity_type_id);
+ }
+ }
$this->installConfig(array('language'));
diff --git a/core/modules/system/src/Tests/Entity/EntityTranslationTest.php b/core/modules/system/src/Tests/Entity/EntityTranslationTest.php
index c896f6f..6289c03 100644
--- a/core/modules/system/src/Tests/Entity/EntityTranslationTest.php
+++ b/core/modules/system/src/Tests/Entity/EntityTranslationTest.php
@@ -24,7 +24,7 @@ class EntityTranslationTest extends EntityLanguageTestBase {
public function testEntityLanguageMethods() {
// All entity variations have to have the same results.
foreach (entity_test_entity_types() as $entity_type) {
- $this->_testEntityLanguageMethods($entity_type);
+ $this->doTestEntityLanguageMethods($entity_type);
}
}
@@ -34,7 +34,8 @@ class EntityTranslationTest extends EntityLanguageTestBase {
* @param string $entity_type
* The entity type to run the tests with.
*/
- protected function _testEntityLanguageMethods($entity_type) {
+ protected function doTestEntityLanguageMethods($entity_type) {
+ $langcode_key = $this->entityManager->getDefinition($entity_type)->getKey('langcode');
$entity = entity_create($entity_type, array(
'name' => 'test',
'user_id' => $this->container->get('current_user')->id(),
@@ -43,7 +44,7 @@ class EntityTranslationTest extends EntityLanguageTestBase {
$entity = entity_create($entity_type, array(
'name' => 'test',
'user_id' => \Drupal::currentUser()->id(),
- 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
+ $langcode_key => LanguageInterface::LANGCODE_NOT_SPECIFIED,
));
$this->assertEqual($entity->language()->getId(), LanguageInterface::LANGCODE_NOT_SPECIFIED, format_string('%entity_type: Entity language not specified.', array('%entity_type' => $entity_type)));
$this->assertFalse($entity->getTranslationLanguages(FALSE), format_string('%entity_type: No translations are available', array('%entity_type' => $entity_type)));
@@ -71,7 +72,7 @@ class EntityTranslationTest extends EntityLanguageTestBase {
// Now, make the entity language-specific by assigning a language and test
// translating it.
$default_langcode = $this->langcodes[0];
- $entity->langcode->value = $default_langcode;
+ $entity->{$langcode_key}->value = $default_langcode;
$entity->{$this->field_name} = array();
$this->assertEqual($entity->language(), \Drupal::languageManager()->getLanguage($this->langcodes[0]), format_string('%entity_type: Entity language retrieved.', array('%entity_type' => $entity_type)));
$this->assertFalse($entity->getTranslationLanguages(FALSE), format_string('%entity_type: No translations are available', array('%entity_type' => $entity_type)));
@@ -133,7 +134,7 @@ class EntityTranslationTest extends EntityLanguageTestBase {
public function testMultilingualProperties() {
// Test all entity variations with data table support.
foreach (entity_test_entity_types(ENTITY_TEST_TYPES_MULTILINGUAL) as $entity_type) {
- $this->_testMultilingualProperties($entity_type);
+ $this->doTestMultilingualProperties($entity_type);
}
}
@@ -143,14 +144,15 @@ class EntityTranslationTest extends EntityLanguageTestBase {
* @param string $entity_type
* The entity type to run the tests with.
*/
- protected function _testMultilingualProperties($entity_type) {
+ protected function doTestMultilingualProperties($entity_type) {
+ $langcode_key = $this->entityManager->getDefinition($entity_type)->getKey('langcode');
$name = $this->randomMachineName();
$uid = mt_rand(0, 127);
$langcode = $this->langcodes[0];
// Create a language neutral entity and check that properties are stored
// as language neutral.
- $entity = entity_create($entity_type, array('name' => $name, 'user_id' => $uid, 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED));
+ $entity = entity_create($entity_type, array('name' => $name, 'user_id' => $uid, $langcode_key => LanguageInterface::LANGCODE_NOT_SPECIFIED));
$entity->save();
$entity = entity_load($entity_type, $entity->id());
$default_langcode = $entity->language()->getId();
@@ -170,7 +172,7 @@ class EntityTranslationTest extends EntityLanguageTestBase {
// Create a language-aware entity and check that properties are stored
// as language-aware.
- $entity = entity_create($entity_type, array('name' => $name, 'user_id' => $uid, 'langcode' => $langcode));
+ $entity = entity_create($entity_type, array('name' => $name, 'user_id' => $uid, $langcode_key => $langcode));
$entity->save();
$entity = entity_load($entity_type, $entity->id());
$default_langcode = $entity->language()->getId();
@@ -235,7 +237,7 @@ class EntityTranslationTest extends EntityLanguageTestBase {
entity_create($entity_type, array(
'user_id' => $properties[$langcode]['user_id'],
'name' => 'some name',
- 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
+ $langcode_key => LanguageInterface::LANGCODE_NOT_SPECIFIED,
))->save();
$entities = entity_load_multiple($entity_type);
@@ -248,12 +250,12 @@ class EntityTranslationTest extends EntityLanguageTestBase {
// explicit parameter.
$entities = entity_load_multiple_by_properties($entity_type, array('name' => $properties[$langcode]['name'][0], 'default_langcode' => 0));
$this->assertEqual(count($entities), 1, format_string('%entity_type: One entity correctly loaded by name translation.', array('%entity_type' => $entity_type)));
- $entities = entity_load_multiple_by_properties($entity_type, array('langcode' => $default_langcode, 'name' => $name));
+ $entities = entity_load_multiple_by_properties($entity_type, array($langcode_key => $default_langcode, 'name' => $name));
$this->assertEqual(count($entities), 1, format_string('%entity_type: One entity correctly loaded by name and language.', array('%entity_type' => $entity_type)));
- $entities = entity_load_multiple_by_properties($entity_type, array('langcode' => $langcode, 'name' => $properties[$langcode]['name'][0]));
+ $entities = entity_load_multiple_by_properties($entity_type, array($langcode_key => $langcode, 'name' => $properties[$langcode]['name'][0]));
$this->assertEqual(count($entities), 0, format_string('%entity_type: No entity loaded by name translation specifying the translation language.', array('%entity_type' => $entity_type)));
- $entities = entity_load_multiple_by_properties($entity_type, array('langcode' => $langcode, 'name' => $properties[$langcode]['name'][0], 'default_langcode' => 0));
+ $entities = entity_load_multiple_by_properties($entity_type, array($langcode_key => $langcode, 'name' => $properties[$langcode]['name'][0], 'default_langcode' => 0));
$this->assertEqual(count($entities), 1, format_string('%entity_type: One entity loaded by name translation and language specifying to look for translations.', array('%entity_type' => $entity_type)));
$entities = entity_load_multiple_by_properties($entity_type, array('user_id' => $properties[$langcode]['user_id'][0], 'default_langcode' => NULL));
$this->assertEqual(count($entities), 2, format_string('%entity_type: Two entities loaded by uid without caring about property translatability.', array('%entity_type' => $entity_type)));
@@ -283,7 +285,7 @@ class EntityTranslationTest extends EntityLanguageTestBase {
->condition('name', $properties[$langcode]['name'], '=', $langcode)
->condition("$this->field_name.value", $field_value, '=', $langcode);
$result = $query
- ->condition('langcode', $default_langcode)
+ ->condition($langcode_key, $default_langcode)
->condition($default_langcode_group)
->condition($langcode_group)
->execute();
@@ -294,11 +296,25 @@ class EntityTranslationTest extends EntityLanguageTestBase {
* Tests the Entity Translation API behavior.
*/
function testEntityTranslationAPI() {
+ // Test all entity variations with data table support.
+ foreach (entity_test_entity_types(ENTITY_TEST_TYPES_MULTILINGUAL) as $entity_type) {
+ $this->doTestEntityTranslationAPI($entity_type);
+ }
+ }
+
+ /**
+ * Executes the Entity Translation API tests for the given entity type.
+ *
+ * @param string $entity_type
+ * The entity type to run the tests with.
+ */
+ protected function doTestEntityTranslationAPI($entity_type) {
$default_langcode = $this->langcodes[0];
$langcode = $this->langcodes[1];
+ $langcode_key = $this->entityManager->getDefinition($entity_type)->getKey('langcode');
$entity = $this->entityManager
- ->getStorage('entity_test_mul')
- ->create(array('name' => $this->randomMachineName(), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED));
+ ->getStorage($entity_type)
+ ->create(array('name' => $this->randomMachineName(), $langcode_key => LanguageInterface::LANGCODE_NOT_SPECIFIED));
$entity->save();
$hooks = $this->getHooksInfo();
@@ -308,7 +324,7 @@ class EntityTranslationTest extends EntityLanguageTestBase {
// retrieve a translation referring to it.
$translation = $entity->getTranslation($langcode);
$this->assertEqual($entity, $translation, 'The translation object corresponding to a non-default language is the entity object itself when the entity is language-neutral.');
- $entity->langcode->value = $default_langcode;
+ $entity->{$langcode_key}->value = $default_langcode;
$translation = $entity->getTranslation($default_langcode);
$this->assertEqual($entity, $translation, 'The translation object corresponding to the default language (explicit) is the entity object itself.');
$translation = $entity->getTranslation(LanguageInterface::LANGCODE_DEFAULT);
@@ -333,7 +349,7 @@ class EntityTranslationTest extends EntityLanguageTestBase {
$translation->save();
$hooks = $this->getHooksInfo();
$this->assertEqual($hooks['entity_translation_insert'], $langcode, 'The generic entity translation insertion hook has fired.');
- $this->assertEqual($hooks['entity_test_mul_translation_insert'], $langcode, 'The entity-type-specific entity translation insertion hook has fired.');
+ $this->assertEqual($hooks[$entity_type . '_translation_insert'], $langcode, 'The entity-type-specific entity translation insertion hook has fired.');
// Check that after loading an entity the language is the default one.
$entity = $this->reloadEntity($entity);
@@ -350,7 +366,7 @@ class EntityTranslationTest extends EntityLanguageTestBase {
$translation->save();
$hooks = $this->getHooksInfo();
$this->assertEqual($hooks['entity_translation_insert'], $langcode2, 'The generic entity translation insertion hook has fired.');
- $this->assertEqual($hooks['entity_test_mul_translation_insert'], $langcode2, 'The entity-type-specific entity translation insertion hook has fired.');
+ $this->assertEqual($hooks[$entity_type . '_translation_insert'], $langcode2, 'The entity-type-specific entity translation insertion hook has fired.');
// Verify that trying to manipulate a translation object referring to a
// removed translation results in exceptions being thrown.
@@ -373,7 +389,7 @@ class EntityTranslationTest extends EntityLanguageTestBase {
$entity->save();
$hooks = $this->getHooksInfo();
$this->assertEqual($hooks['entity_translation_delete'], $langcode2, 'The generic entity translation deletion hook has fired.');
- $this->assertEqual($hooks['entity_test_mul_translation_delete'], $langcode2, 'The entity-type-specific entity translation deletion hook has fired.');
+ $this->assertEqual($hooks[$entity_type . '_translation_delete'], $langcode2, 'The entity-type-specific entity translation deletion hook has fired.');
$entity = $this->reloadEntity($entity);
$this->assertFalse($entity->hasTranslation($langcode2), 'The translation does not appear among available translations after saving the entity.');
@@ -460,6 +476,19 @@ class EntityTranslationTest extends EntityLanguageTestBase {
* Tests language fallback applied to field and entity translations.
*/
function testLanguageFallback() {
+ // Test all entity variations with data table support.
+ foreach (entity_test_entity_types(ENTITY_TEST_TYPES_MULTILINGUAL) as $entity_type) {
+ $this->doTestLanguageFallback($entity_type);
+ }
+ }
+
+ /**
+ * Executes the language fallback test for the given entity type.
+ *
+ * @param string $entity_type
+ * The entity type to run the tests with.
+ */
+ protected function doTestLanguageFallback($entity_type) {
$current_langcode = $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId();
$this->langcodes[] = $current_langcode;
@@ -472,10 +501,15 @@ class EntityTranslationTest extends EntityLanguageTestBase {
$default_langcode = $this->langcodes[0];
$langcode = $this->langcodes[1];
$langcode2 = $this->langcodes[2];
+ $langcode_key = $this->entityManager->getDefinition($entity_type)->getKey('langcode');
+ $languages = $this->languageManager->getLanguages();
+ $language = ConfigurableLanguage::load($languages[$langcode]->getId());
+ $language->set('weight', 1);
+ $language->save();
+ $this->languageManager->reset();
- $entity_type = 'entity_test_mul';
$controller = $this->entityManager->getStorage($entity_type);
- $entity = $controller->create(array('langcode' => $default_langcode) + $values[$default_langcode]);
+ $entity = $controller->create(array($langcode_key => $default_langcode) + $values[$default_langcode]);
$entity->save();
$entity->addTranslation($langcode, $values[$langcode]);
@@ -487,7 +521,6 @@ class EntityTranslationTest extends EntityLanguageTestBase {
$this->assertEqual($translation->language()->getId(), $default_langcode, 'The current translation language matches the expected one.');
// Check that language fallback respects language weight by default.
- $languages = $this->languageManager->getLanguages();
$language = ConfigurableLanguage::load($languages[$langcode]->getId());
$language->set('weight', -1);
$language->save();
@@ -502,7 +535,7 @@ class EntityTranslationTest extends EntityLanguageTestBase {
$this->assertEqual($current_langcode, $translation->language()->getId(), 'The current translation language matches the current language.');
// Check that if the entity has no translation no fallback is applied.
- $entity2 = $controller->create(array('langcode' => $default_langcode));
+ $entity2 = $controller->create(array($langcode_key => $default_langcode));
// Get an view builder.
$controller = $this->entityManager->getViewBuilder($entity_type);
$entity2_build = $controller->view($entity2);
@@ -574,14 +607,27 @@ class EntityTranslationTest extends EntityLanguageTestBase {
* Tests that changing entity language does not break field language.
*/
public function testLanguageChange() {
- $entity_type = 'entity_test_mul';
+ // Test all entity variations with data table support.
+ foreach (entity_test_entity_types(ENTITY_TEST_TYPES_MULTILINGUAL) as $entity_type) {
+ $this->doTestLanguageChange($entity_type);
+ }
+ }
+
+ /**
+ * Executes the entity language change test for the given entity type.
+ *
+ * @param string $entity_type
+ * The entity type to run the tests with.
+ */
+ protected function doTestLanguageChange($entity_type) {
+ $langcode_key = $this->entityManager->getDefinition($entity_type)->getKey('langcode');
$controller = $this->entityManager->getStorage($entity_type);
$langcode = $this->langcodes[0];
// check that field languages match entity language regardless of field
// translatability.
$values = array(
- 'langcode' => $langcode,
+ $langcode_key => $langcode,
$this->field_name => $this->randomMachineName(),
$this->untranslatable_field_name => $this->randomMachineName(),
);
@@ -593,7 +639,7 @@ class EntityTranslationTest extends EntityLanguageTestBase {
// Check that field languages keep matching entity language even after
// changing it.
$langcode = $this->langcodes[1];
- $entity->langcode->value = $langcode;
+ $entity->{$langcode_key}->value = $langcode;
foreach (array($this->field_name, $this->untranslatable_field_name) as $field_name) {
$this->assertEqual($entity->get($field_name)->getLangcode(), $langcode, 'Field language works as expected after changing entity language.');
}
@@ -602,7 +648,7 @@ class EntityTranslationTest extends EntityLanguageTestBase {
// field values and untranslatable ones.
$langcode = $this->langcodes[0];
$entity->addTranslation($this->langcodes[2], array($this->field_name => $this->randomMachineName()));
- $entity->langcode->value = $langcode;
+ $entity->{$langcode_key}->value = $langcode;
foreach (array($this->field_name, $this->untranslatable_field_name) as $field_name) {
$this->assertEqual($entity->get($field_name)->getLangcode(), $langcode, 'Field language works as expected after translating the entity and changing language.');
}
@@ -611,7 +657,7 @@ class EntityTranslationTest extends EntityLanguageTestBase {
// language causes an exception to be thrown.
$message = 'An exception is thrown when setting the default language to an existing translation language';
try {
- $entity->langcode->value = $this->langcodes[2];
+ $entity->{$langcode_key}->value = $this->langcodes[2];
$this->fail($message);
}
catch (\InvalidArgumentException $e) {
diff --git a/core/modules/system/src/Tests/Entity/EntityUUIDTest.php b/core/modules/system/src/Tests/Entity/EntityUUIDTest.php
index 5f3b6e1..f2f8aff 100644
--- a/core/modules/system/src/Tests/Entity/EntityUUIDTest.php
+++ b/core/modules/system/src/Tests/Entity/EntityUUIDTest.php
@@ -17,9 +17,12 @@ class EntityUUIDTest extends EntityUnitTestBase {
protected function setUp() {
parent::setUp();
- $this->installEntitySchema('entity_test_rev');
- $this->installEntitySchema('entity_test_mul');
- $this->installEntitySchema('entity_test_mulrev');
+ foreach (entity_test_entity_types() as $entity_type_id) {
+ // The entity_test schema is installed by the parent.
+ if ($entity_type_id != 'entity_test') {
+ $this->installEntitySchema($entity_type_id);
+ }
+ }
}
/**
diff --git a/core/modules/system/src/Tests/Entity/EntityValidationTest.php b/core/modules/system/src/Tests/Entity/EntityValidationTest.php
index 8fdcf82..719b783 100644
--- a/core/modules/system/src/Tests/Entity/EntityValidationTest.php
+++ b/core/modules/system/src/Tests/Entity/EntityValidationTest.php
@@ -42,10 +42,6 @@ class EntityValidationTest extends EntityUnitTestBase {
protected function setUp() {
parent::setUp();
- $this->installEntitySchema('entity_test_rev');
- $this->installEntitySchema('entity_test_mul');
- $this->installEntitySchema('entity_test_mulrev');
-
// Create the test field.
entity_test_install();
@@ -114,7 +110,8 @@ class EntityValidationTest extends EntityUnitTestBase {
$this->assertEqual($violations[0]->getMessage(), t('%name: may not be longer than @max characters.', array('%name' => 'UUID', '@max' => 128)));
$test_entity = clone $entity;
- $test_entity->langcode->value = $this->randomString(13);
+ $langcode_key = $this->entityManager->getDefinition($entity_type)->getKey('langcode');
+ $test_entity->{$langcode_key}->value = $this->randomString(13);
$violations = $test_entity->validate();
$this->assertEqual($violations->count(), 1, 'Validation failed.');
$this->assertEqual($violations[0]->getMessage(), t('This value is too long. It should have %limit characters or less.', array('%limit' => '12')));
diff --git a/core/modules/system/src/Tests/Installer/InstallerTranslationTest.php b/core/modules/system/src/Tests/Installer/InstallerTranslationTest.php
index 5707234..8d9305c 100644
--- a/core/modules/system/src/Tests/Installer/InstallerTranslationTest.php
+++ b/core/modules/system/src/Tests/Installer/InstallerTranslationTest.php
@@ -53,9 +53,11 @@ class InstallerTranslationTest extends InstallerTestBase {
$this->assertResponse(200);
$account = User::load(0);
- $this->assertEqual($account->language()->getId(), 'de', 'Anonymous user is German.');
+ $this->assertEqual($account->language()->getId(), 'en', 'Anonymous user is English.');
$account = User::load(1);
- $this->assertEqual($account->language()->getId(), 'de', 'Administrator user is German.');
+ $this->assertEqual($account->language()->getId(), 'en', 'Administrator user is English.');
+ $account = $this->drupalCreateUser();
+ $this->assertEqual($account->language()->getId(), 'de', 'New user is German.');
// Ensure that we can enable basic_auth on a non-english site.
$this->drupalPostForm('admin/modules', array('modules[Web services][basic_auth][enable]' => TRUE), t('Save configuration'));
diff --git a/core/modules/system/tests/modules/entity_test/entity_test.install b/core/modules/system/tests/modules/entity_test/entity_test.install
index 4d2e0f3..1a6d9a2 100644
--- a/core/modules/system/tests/modules/entity_test/entity_test.install
+++ b/core/modules/system/tests/modules/entity_test/entity_test.install
@@ -9,13 +9,7 @@
* Implements hook_install().
*/
function entity_test_install() {
- $entity_types = array(
- 'entity_test',
- 'entity_test_rev',
- 'entity_test_mul',
- 'entity_test_mulrev',
- );
- foreach ($entity_types as $entity_type) {
+ foreach (entity_test_entity_types() as $entity_type) {
// Auto-create fields for testing.
entity_create('field_storage_config', array(
'entity_type' => $entity_type,
diff --git a/core/modules/system/tests/modules/entity_test/entity_test.module b/core/modules/system/tests/modules/entity_test/entity_test.module
index 08fa564..6a6c6e2 100644
--- a/core/modules/system/tests/modules/entity_test/entity_test.module
+++ b/core/modules/system/tests/modules/entity_test/entity_test.module
@@ -52,6 +52,7 @@ function entity_test_entity_types($filter = NULL) {
}
if ($filter != ENTITY_TEST_TYPES_REVISABLE) {
$types[] = 'entity_test_mul';
+ $types[] = 'entity_test_mul_langcode_key';
}
if ($filter != ENTITY_TEST_TYPES_MULTILINGUAL) {
$types[] = 'entity_test_rev';
@@ -429,6 +430,34 @@ function entity_test_entity_test_mul_translation_delete(EntityInterface $transla
}
/**
+ * Implements hook_ENTITY_TYPE_translation_insert().
+ */
+function entity_test_entity_test_mulrev_translation_insert(EntityInterface $translation) {
+ _entity_test_record_hooks('entity_test_mulrev_translation_insert', $translation->language()->getId());
+}
+
+/**
+ * Implements hook_ENTITY_TYPE_translation_delete().
+ */
+function entity_test_entity_test_mulrev_translation_delete(EntityInterface $translation) {
+ _entity_test_record_hooks('entity_test_mulrev_translation_delete', $translation->language()->getId());
+}
+
+/**
+ * Implements hook_ENTITY_TYPE_translation_insert().
+ */
+function entity_test_entity_test_mul_langcode_key_translation_insert(EntityInterface $translation) {
+ _entity_test_record_hooks('entity_test_mul_langcode_key_translation_insert', $translation->language()->getId());
+}
+
+/**
+ * Implements hook_ENTITY_TYPE_translation_delete().
+ */
+function entity_test_entity_test_mul_langcode_key_translation_delete(EntityInterface $translation) {
+ _entity_test_record_hooks('entity_test_mul_langcode_key_translation_delete', $translation->language()->getId());
+}
+
+/**
* Field default value callback.
*
* @param \Drupal\Core\Entity\FieldableEntityInterface $entity
diff --git a/core/modules/system/tests/modules/entity_test/entity_test.routing.yml b/core/modules/system/tests/modules/entity_test/entity_test.routing.yml
index 8d1283b..7b4ccbc 100644
--- a/core/modules/system/tests/modules/entity_test/entity_test.routing.yml
+++ b/core/modules/system/tests/modules/entity_test/entity_test.routing.yml
@@ -6,34 +6,6 @@ entity.entity_test.canonical:
requirements:
_access: 'TRUE'
-entity.entity_test.delete_form:
- path: '/entity_test/delete/entity_test/{entity_test}'
- defaults:
- _entity_form: entity_test.delete
- requirements:
- _access: 'TRUE'
-
-entity.entity_test_mul.delete_form:
- path: '/entity_test/delete/entity_test_mul/{entity_test_mul}'
- defaults:
- _entity_form: entity_test_mul.delete
- requirements:
- _access: 'TRUE'
-
-entity.entity_test_mulrev.delete_form:
- path: '/entity_test/delete/entity_test_mulrev/{entity_test_mulrev}'
- defaults:
- _entity_form: entity_test_mulrev.delete
- requirements:
- _access: 'TRUE'
-
-entity.entity_test_rev.delete_form:
- path: '/entity_test/delete/entity_test_rev/{entity_test_rev}'
- defaults:
- _entity_form: entity_test_rev.delete
- requirements:
- _access: 'TRUE'
-
entity.entity_test.render_options:
path: '/entity_test_converter/{foo}'
options:
diff --git a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTest.php b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTest.php
index 9200270..d9800be 100644
--- a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTest.php
+++ b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTest.php
@@ -37,7 +37,8 @@ use Drupal\user\UserInterface;
* "id" = "id",
* "uuid" = "uuid",
* "bundle" = "type",
- * "label" = "name"
+ * "label" = "name",
+ * "langcode" = "langcode",
* },
* links = {
* "canonical" = "entity.entity_test.canonical",
diff --git a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestDefaultValue.php b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestDefaultValue.php
index 1c1797f..28905da 100644
--- a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestDefaultValue.php
+++ b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestDefaultValue.php
@@ -20,7 +20,8 @@ use Drupal\Core\Field\BaseFieldDefinition;
* entity_keys = {
* "id" = "id",
* "uuid" = "uuid",
- * "bundle" = "type"
+ * "bundle" = "type",
+ * "langcode" = "langcode"
* }
* )
*/
diff --git a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMul.php b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMul.php
index 402936f..cabb610 100644
--- a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMul.php
+++ b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMul.php
@@ -34,7 +34,8 @@ use Drupal\entity_test\Entity\EntityTest;
* "id" = "id",
* "uuid" = "uuid",
* "bundle" = "type",
- * "label" = "name"
+ * "label" = "name",
+ * "langcode" = "langcode",
* },
* links = {
* "canonical" = "entity.entity_test_mul.edit_form",
diff --git a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulDefaultValue.php b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulDefaultValue.php
index 33369ac..fa3a60e 100644
--- a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulDefaultValue.php
+++ b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulDefaultValue.php
@@ -33,7 +33,8 @@ use Drupal\Core\Field\BaseFieldDefinition;
* "id" = "id",
* "uuid" = "uuid",
* "bundle" = "type",
- * "label" = "name"
+ * "label" = "name",
+ * "langcode" = "langcode"
* },
* links = {
* "canonical" = "entity.entity_test_mul.edit_form",
diff --git a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulLangcodeKey.php b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulLangcodeKey.php
new file mode 100644
index 0000000..575d125
--- /dev/null
+++ b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulLangcodeKey.php
@@ -0,0 +1,58 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\entity_test\Entity\EntityTestMul.
+ */
+
+namespace Drupal\entity_test\Entity;
+
+use Drupal\Core\Entity\EntityTypeInterface;
+
+/**
+ * Defines a test entity class using a custom langcode entity key.
+ *
+ * @ContentEntityType(
+ * id = "entity_test_mul_langcode_key",
+ * label = @Translation("Test entity - data table - langcode key"),
+ * handlers = {
+ * "view_builder" = "Drupal\entity_test\EntityTestViewBuilder",
+ * "access" = "Drupal\entity_test\EntityTestAccessControlHandler",
+ * "form" = {
+ * "default" = "Drupal\entity_test\EntityTestForm",
+ * "delete" = "Drupal\entity_test\EntityTestDeleteForm"
+ * },
+ * "translation" = "Drupal\content_translation\ContentTranslationHandler",
+ * "views_data" = "Drupal\views\EntityViewsData"
+ * },
+ * base_table = "entity_test_mul_langcode_key",
+ * data_table = "entity_test_mul_langcode_key_field_data",
+ * translatable = TRUE,
+ * entity_keys = {
+ * "id" = "id",
+ * "uuid" = "uuid",
+ * "bundle" = "type",
+ * "label" = "name",
+ * "langcode" = "custom_langcode_key",
+ * },
+ * links = {
+ * "canonical" = "entity.entity_test_mul_langcode_key.edit_form",
+ * "edit-form" = "entity.entity_test_mul_langcode_key.edit_form",
+ * "delete-form" = "entity.entity_test_mul_langcode_key.delete_form",
+ * },
+ * field_ui_base_route = "entity.entity_test_mul_langcode_key.admin_form",
+ * )
+ */
+class EntityTestMulLangcodeKey extends EntityTest {
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
+ $fields = parent::baseFieldDefinitions($entity_type);
+ $fields['custom_langcode_key'] = $fields['langcode'];
+ unset($fields['langcode']);
+ return $fields;
+ }
+
+}
diff --git a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulRev.php b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulRev.php
index b5fc86f..7fa29a9 100644
--- a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulRev.php
+++ b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulRev.php
@@ -18,6 +18,7 @@ use Drupal\entity_test\Entity\EntityTestRev;
* id = "entity_test_mulrev",
* label = @Translation("Test entity - revisions and data table"),
* handlers = {
+ * "view_builder" = "Drupal\entity_test\EntityTestViewBuilder",
* "access" = "Drupal\entity_test\EntityTestAccessControlHandler",
* "form" = {
* "default" = "Drupal\entity_test\EntityTestForm",
@@ -34,8 +35,10 @@ use Drupal\entity_test\Entity\EntityTestRev;
* entity_keys = {
* "id" = "id",
* "uuid" = "uuid",
+ * "bundle" = "type",
* "revision" = "revision_id",
- * "bundle" = "type"
+ * "label" = "name",
+ * "langcode" = "langcode",
* },
* links = {
* "canonical" = "entity.entity_test_mulrev.edit_form",
diff --git a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestRev.php b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestRev.php
index 3b40ed9..f5bee90 100644
--- a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestRev.php
+++ b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestRev.php
@@ -34,6 +34,7 @@ use Drupal\entity_test\Entity\EntityTest;
* "revision" = "revision_id",
* "bundle" = "type",
* "label" = "name",
+ * "langcode" = "langcode",
* },
* links = {
* "canonical" = "entity.entity_test_rev.edit_form",
diff --git a/core/modules/system/tests/modules/entity_test/src/Routing/EntityTestRoutes.php b/core/modules/system/tests/modules/entity_test/src/Routing/EntityTestRoutes.php
index d3ca362..03e147c 100644
--- a/core/modules/system/tests/modules/entity_test/src/Routing/EntityTestRoutes.php
+++ b/core/modules/system/tests/modules/entity_test/src/Routing/EntityTestRoutes.php
@@ -34,7 +34,7 @@ class EntityTestRoutes {
);
$routes["entity.$entity_type_id.edit_form"] = new Route(
- "$entity_type_id/manage/{" . $entity_type_id . '}',
+ $entity_type_id . '/manage/{' . $entity_type_id . '}',
array('_controller' => '\Drupal\entity_test\Controller\EntityTestController::testEdit', 'entity_type_id' => $entity_type_id),
array('_permission' => 'administer entity_test content'),
array('parameters' => array(
@@ -42,6 +42,12 @@ class EntityTestRoutes {
))
);
+ $routes["entity.$entity_type_id.delete_form"] = new Route(
+ 'entity_test/delete/' . $entity_type_id . '/{' . $entity_type_id . '}',
+ array('_entity_form' => $entity_type_id . '.delete'),
+ array('_permission' => 'administer entity_test content')
+ );
+
$routes["entity.$entity_type_id.admin_form"] = new Route(
"$entity_type_id/structure/{bundle}",
array('_controller' => '\Drupal\entity_test\Controller\EntityTestController::testAdmin'),
diff --git a/core/modules/taxonomy/src/Entity/Term.php b/core/modules/taxonomy/src/Entity/Term.php
index 4710021..93f9009 100644
--- a/core/modules/taxonomy/src/Entity/Term.php
+++ b/core/modules/taxonomy/src/Entity/Term.php
@@ -40,6 +40,7 @@ use Drupal\taxonomy\TermInterface;
* "id" = "tid",
* "bundle" = "vid",
* "label" = "name",
+ * "langcode" = "langcode",
* "uuid" = "uuid"
* },
* bundle_entity_type = "taxonomy_vocabulary",
diff --git a/core/modules/user/src/Entity/User.php b/core/modules/user/src/Entity/User.php
index 629ce9c..2ac5fec 100644
--- a/core/modules/user/src/Entity/User.php
+++ b/core/modules/user/src/Entity/User.php
@@ -44,6 +44,7 @@ use Drupal\user\UserInterface;
* translatable = TRUE,
* entity_keys = {
* "id" = "uid",
+ * "langcode" = "langcode",
* "uuid" = "uuid"
* },
* links = {
diff --git a/core/modules/views/src/Entity/Render/TranslationLanguageRenderer.php b/core/modules/views/src/Entity/Render/TranslationLanguageRenderer.php
index d03e5d5..9b0e0da 100644
--- a/core/modules/views/src/Entity/Render/TranslationLanguageRenderer.php
+++ b/core/modules/views/src/Entity/Render/TranslationLanguageRenderer.php
@@ -34,11 +34,11 @@ class TranslationLanguageRenderer extends DefaultLanguageRenderer {
// If the data table is defined, we use the translation language as render
// language, otherwise we fall back to the default entity language, which is
// stored in the revision table for revisionable entity types.
- $entity_info = $this->view->rowPlugin->entityManager->getDefinition($this->entityType->id());
+ $langcode_key = $this->entityType->getKey('langcode');
foreach (array('data_table', 'revision_table', 'base_table') as $key) {
- if ($table = $entity_info->get($key)) {
+ if ($table = $this->entityType->get($key)) {
$table_alias = $query->ensureTable($table);
- $this->langcodeAlias = $query->addField($table_alias, 'langcode');
+ $this->langcodeAlias = $query->addField($table_alias, $langcode_key);
break;
}
}
diff --git a/core/modules/views/src/EntityViewsData.php b/core/modules/views/src/EntityViewsData.php
index 9f361c7..cb30422 100644
--- a/core/modules/views/src/EntityViewsData.php
+++ b/core/modules/views/src/EntityViewsData.php
@@ -390,7 +390,7 @@ class EntityViewsData implements EntityHandlerInterface, EntityViewsDataInterfac
*/
protected function processViewsDataForLanguage($table, FieldDefinitionInterface $field_definition, array &$views_field, $field_column_name) {
// Apply special titles for the langcode field.
- if ($field_definition->getName() == 'langcode') {
+ if ($field_definition->getName() == $this->entityType->getKey('langcode')) {
if ($table == $this->entityType->getDataTable() || $table == $this->entityType->getRevisionDataTable()) {
$views_field['title'] = $this->t('Translation language');
}
diff --git a/core/modules/views/tests/src/Unit/EntityViewsDataTest.php b/core/modules/views/tests/src/Unit/EntityViewsDataTest.php
index e9c5a60..c1aac0f 100644
--- a/core/modules/views/tests/src/Unit/EntityViewsDataTest.php
+++ b/core/modules/views/tests/src/Unit/EntityViewsDataTest.php
@@ -87,7 +87,7 @@ class EntityViewsDataTest extends UnitTestCase {
'base_table' => 'entity_test',
'id' => 'entity_test',
'label' => 'Entity test',
- 'entity_keys' => ['id' => 'id'],
+ 'entity_keys' => ['id' => 'id', 'langcode' => 'langcode'],
'provider' => 'entity_test',
]);
diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php
index ddfbd81..3f95ed9 100644
--- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php
+++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php
@@ -111,6 +111,7 @@ class ConfigEntityStorageTest extends UnitTestCase {
->will($this->returnValueMap(array(
array('id', 'id'),
array('uuid', 'uuid'),
+ array('langcode', 'langcode'),
)));
$this->entityType->expects($this->any())
->method('id')
diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php
index fa7c14b..ce6cf27 100644
--- a/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php
@@ -554,7 +554,7 @@ class EntityManagerTest extends UnitTestCase {
* @covers ::getFieldDefinitions
*/
public function testGetFieldDefinitionsWithCaching() {
- $field_definition = $this->setUpEntityWithFieldDefinition(FALSE, 'id', 0);
+ $field_definition = $this->setUpEntityWithFieldDefinition(FALSE, 'id');
$expected = array('id' => $field_definition);
@@ -594,7 +594,7 @@ class EntityManagerTest extends UnitTestCase {
* @covers ::getFieldStorageDefinitions
*/
public function testGetFieldStorageDefinitionsWithCaching() {
- $field_definition = $this->setUpEntityWithFieldDefinition(TRUE, 'id', 0);
+ $field_definition = $this->setUpEntityWithFieldDefinition(TRUE, 'id');
$field_storage_definition = $this->getMock('\Drupal\Core\Field\FieldStorageDefinitionInterface');
$field_storage_definition->expects($this->any())
->method('getName')
@@ -658,7 +658,7 @@ class EntityManagerTest extends UnitTestCase {
* @expectedException \LogicException
*/
public function testGetBaseFieldDefinitionsInvalidDefinition() {
- $langcode_definition = $this->setUpEntityWithFieldDefinition(FALSE, 'langcode');
+ $langcode_definition = $this->setUpEntityWithFieldDefinition(FALSE, 'langcode', array('langcode' => 'langcode'));
$langcode_definition->expects($this->once())
->method('isTranslatable')
->will($this->returnValue(TRUE));
@@ -710,11 +710,14 @@ class EntityManagerTest extends UnitTestCase {
* ModuleHandlerInterface::invokeAll() implementation. Defaults to FALSE.
* @param string $field_definition_id
* (optional) The ID to use for the field definition. Defaults to 'id'.
+ * @param array $entity_keys
+ * (optional) An array of entity keys for the mocked entity type. Defaults
+ * to an empty array.
*
* @return \Drupal\Core\Field\BaseFieldDefinition|\PHPUnit_Framework_MockObject_MockObject
* A field definition object.
*/
- protected function setUpEntityWithFieldDefinition($custom_invoke_all = FALSE, $field_definition_id = 'id') {
+ protected function setUpEntityWithFieldDefinition($custom_invoke_all = FALSE, $field_definition_id = 'id', $entity_keys = array()) {
$entity_type = $this->getMock('Drupal\Core\Entity\EntityTypeInterface');
$entity = $this->getMockBuilder('Drupal\Tests\Core\Entity\EntityManagerTestEntity')
->disableOriginalConstructor()
@@ -726,7 +729,7 @@ class EntityManagerTest extends UnitTestCase {
->will($this->returnValue($entity_class));
$entity_type->expects($this->any())
->method('getKeys')
- ->will($this->returnValue(array()));
+ ->will($this->returnValue($entity_keys));
$entity_type->expects($this->any())
->method('isSubclassOf')
->with($this->equalTo('\Drupal\Core\Entity\FieldableEntityInterface'))
diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php
index 4ff2f23..c6d70ce 100644
--- a/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php
@@ -69,9 +69,9 @@ class EntityTypeTest extends UnitTestCase {
*/
public function providerTestGetKeys() {
return array(
- array(array(), array('revision' => '', 'bundle' => '')),
- array(array('id' => 'id'), array('id' => 'id', 'revision' => '', 'bundle' => '')),
- array(array('bundle' => 'bundle'), array('bundle' => 'bundle', 'revision' => '')),
+ array(array(), array('revision' => '', 'bundle' => '', 'langcode' => '')),
+ array(array('id' => 'id'), array('id' => 'id', 'revision' => '', 'bundle' => '', 'langcode' => '')),
+ array(array('bundle' => 'bundle'), array('bundle' => 'bundle', 'revision' => '', 'langcode' => '')),
);
}
diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php
index 6535732..a531489 100644
--- a/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php
@@ -233,6 +233,11 @@ class EntityUnitTest extends UnitTestCase {
* @covers ::language
*/
public function testLanguage() {
+ $this->entityType->expects($this->any())
+ ->method('getKey')
+ ->will($this->returnValueMap(array(
+ array('langcode', 'langcode'),
+ )));
$this->assertSame('en', $this->entity->language()->getId());
}
diff --git a/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php
index ee10e54..300151a 100644
--- a/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php
@@ -96,6 +96,7 @@ class KeyValueEntityStorageTest extends UnitTestCase {
->will($this->returnValueMap(array(
array('id', 'id'),
array('uuid', $uuid_key),
+ array('langcode', 'langcode'),
)));
$this->entityType->expects($this->atLeastOnce())
->method('id')
diff --git a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php
index a3a7013..82ef89b 100644
--- a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php
@@ -499,6 +499,7 @@ class SqlContentEntityStorageSchemaTest extends UnitTestCase {
'id' => 'entity_test',
'entity_keys' => array(
'id' => 'id',
+ 'langcode' => 'langcode',
),
));
@@ -592,6 +593,7 @@ class SqlContentEntityStorageSchemaTest extends UnitTestCase {
'entity_keys' => array(
'id' => 'id',
'revision' => 'revision_id',
+ 'langcode' => 'langcode',
),
));
diff --git a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php
index cfa5cd9..2f0bd10 100644
--- a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php
@@ -607,6 +607,7 @@ class SqlContentEntityStorageTest extends UnitTestCase {
array('id', $entity_keys['id']),
array('uuid', $entity_keys['uuid']),
array('bundle', $entity_keys['bundle']),
+ array('langcode', $entity_keys['langcode']),
)));
$this->setUpEntityStorage();
@@ -667,6 +668,7 @@ class SqlContentEntityStorageTest extends UnitTestCase {
array('id', $entity_keys['id']),
array('uuid', $entity_keys['uuid']),
array('bundle', $entity_keys['bundle']),
+ array('langcode', $entity_keys['langcode']),
)));
$this->setUpEntityStorage();
@@ -733,6 +735,7 @@ class SqlContentEntityStorageTest extends UnitTestCase {
array('uuid', $entity_keys['uuid']),
array('bundle', $entity_keys['bundle']),
array('revision', $entity_keys['revision']),
+ array('langcode', $entity_keys['langcode']),
)));
$this->setUpEntityStorage();
@@ -854,6 +857,7 @@ class SqlContentEntityStorageTest extends UnitTestCase {
array('uuid', $entity_keys['uuid']),
array('bundle', $entity_keys['bundle']),
array('revision', $entity_keys['revision']),
+ array('langcode', $entity_keys['langcode']),
)));
$this->setUpEntityStorage();