diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php index 126275a..6209b05 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php @@ -107,7 +107,6 @@ class ConfigEntityStorage extends EntityStorageBase implements ConfigEntityStora public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, StorageInterface $config_storage, UuidInterface $uuid_service, LanguageManagerInterface $language_manager) { parent::__construct($entity_type); - $this->idKey = $this->entityType->getKey('id'); $this->statusKey = $this->entityType->getKey('status'); $this->configFactory = $config_factory; @@ -257,7 +256,7 @@ public function create(array $values = array()) { $class::preCreate($this, $values); // Set default language to site default if not provided. - $values += array('langcode' => $this->languageManager->getDefaultLanguage()->id); + $values += array($this->languageKey => $this->languageManager->getDefaultLanguage()->id); $entity = new $class($values, $this->entityTypeId); // Mark this entity as new, so isNew() returns TRUE. This does not check diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityType.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityType.php index 1731ac4..9e57681 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityType.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityType.php @@ -93,8 +93,11 @@ public function getConfigPrefix() { * {@inheritdoc} */ public function getKeys() { - // Always add a default 'uuid' key. - return array('uuid' => 'uuid') + parent::getKeys(); + // Always add default 'uuid' and 'language' keys. + return array( + 'uuid' => 'uuid', + 'language' => 'langcode', + ) + parent::getKeys(); } diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php index 992c728..19a3520 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php @@ -80,6 +80,13 @@ protected $languages; /** + * The language entity key. + * + * @var string + */ + protected $languageKey; + + /** * Language code identifying the entity active language. * * This is the language field accessors will use to determine which field @@ -135,6 +142,7 @@ public function __construct(array $values, $entity_type, $bundle = FALSE, $trans $this->entityTypeId = $entity_type; $this->bundle = $bundle ? $bundle : $this->entityTypeId; $this->languages = $this->languageManager()->getLanguages(Language::STATE_ALL); + $this->languageKey = $this->getEntityType()->getKey('language'); foreach ($values as $key => $value) { // If the key matches an existing property set the value to the property @@ -444,7 +452,7 @@ protected function getTranslatedField($name, $langcode) { */ public function set($name, $value, $notify = TRUE) { // If default language changes we need to react to that. - $notify = $name == 'langcode'; + $notify = ($name == $this->languageKey); $this->get($name)->setValue($value, $notify); } @@ -552,7 +560,7 @@ public function language() { */ protected function setDefaultLangcode() { // Get the language code if the property exists. - if ($this->hasField('langcode') && ($item = $this->get('langcode')) && isset($item->language)) { + if ($this->hasField($this->languageKey) && ($item = $this->get($this->languageKey)) && isset($item->language)) { $this->defaultLangcode = $item->language->id; } if (empty($this->defaultLangcode)) { @@ -561,8 +569,8 @@ protected function setDefaultLangcode() { } // 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'][Language::LANGCODE_DEFAULT]->setLangcode($this->defaultLangcode); + if (!empty($this->fields[$this->languageKey])) { + $this->fields[$this->languageKey][Language::LANGCODE_DEFAULT]->setLangcode($this->defaultLangcode); } } @@ -584,7 +592,7 @@ protected function updateFieldLangcodes($langcode) { * {@inheritdoc} */ public function onChange($name) { - if ($name == 'langcode') { + if ($name == $this->languageKey) { $this->setDefaultLangcode(); if (isset($this->translations[$this->defaultLangcode])) { $message = String::format('A translation already exists for the specified language (@langcode).', array('@langcode' => $this->defaultLangcode)); @@ -706,8 +714,12 @@ public function addTranslation($langcode, array $values = array()) { // 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->languageKey => $langcode, + ); $entity = $this->entityManager() ->getStorage($this->getEntityTypeId()) ->create($default_values); diff --git a/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php index cc97849..c87c2eb 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php @@ -51,6 +51,15 @@ class ContentEntityDatabaseStorage extends ContentEntityStorageBase { protected $dataTable; /** + * Name of entity's default language database table field. + * + * Has the value FALSE if this entity does not have multilingual support. + * + * @var string + */ + protected $defaultLanguageKey = FALSE; + + /** * The table that stores revision field data if the entity supports revisions. * * @var string @@ -122,6 +131,7 @@ public function __construct(EntityTypeInterface $entity_type, Connection $databa // Check if the entity type has a dedicated table for fields. if ($data_table = $this->entityType->getDataTable()) { $this->dataTable = $data_table; + $this->defaultLanguageKey = $this->entityType->getKey('default_language'); // Entity types having both revision and translation support should always // define a revision data table. if ($this->revisionTable && $revision_data_table = $this->entityType->getRevisionDataTable()) { @@ -279,7 +289,7 @@ protected function attachPropertyData(array &$entities) { // Field values in default language are stored with // Language::LANGCODE_DEFAULT as key. - $langcode = empty($values['default_langcode']) ? $values['langcode'] : Language::LANGCODE_DEFAULT; + $langcode = empty($values[$this->defaultLanguageKey]) ? $values[$this->languageKey] : Language::LANGCODE_DEFAULT; $translations[$id][$langcode] = TRUE; foreach (array_keys($field_definitions) as $field_name) { @@ -357,13 +367,13 @@ protected function buildPropertyQuery(QueryInterface $entity_query, array $value // apply to the default language. See http://drupal.org/node/1866330. // Default to the original entity language if not explicitly specified // otherwise. - if (!array_key_exists('default_langcode', $values)) { - $values['default_langcode'] = 1; + if (!array_key_exists($this->defaultLanguageKey, $values)) { + $values[$this->defaultLanguageKey] = 1; } // If the 'default_langcode' flag is explicitly not set, we do not care // whether the queried values are in the original entity language or not. - elseif ($values['default_langcode'] === NULL) { - unset($values['default_langcode']); + elseif ($values[$this->defaultLanguageKey] === NULL) { + unset($values[$this->defaultLanguageKey]); } } diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php index 2300f60..b739e9b 100644 --- a/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -286,7 +286,8 @@ public function access($operation, AccountInterface $account = NULL) { * {@inheritdoc} */ public function language() { - $language = $this->languageManager()->getLanguage($this->langcode); + $langcode = $this->{$this->getEntityType()->getKey('language')}; + $language = $this->languageManager()->getLanguage($langcode); if (!$language) { // Make sure we return a proper language object. $language = new Language(array('id' => Language::LANGCODE_NOT_SPECIFIED)); @@ -297,6 +298,13 @@ public function language() { /** * {@inheritdoc} */ + public function langcode() { + return $this->language()->id; + } + + /** + * {@inheritdoc} + */ public function save() { return $this->entityManager()->getStorage($this->entityTypeId)->save($this); } diff --git a/core/lib/Drupal/Core/Entity/EntityDatabaseStorage.php b/core/lib/Drupal/Core/Entity/EntityDatabaseStorage.php index c25ff56..d92072d 100644 --- a/core/lib/Drupal/Core/Entity/EntityDatabaseStorage.php +++ b/core/lib/Drupal/Core/Entity/EntityDatabaseStorage.php @@ -82,12 +82,6 @@ public function __construct(EntityTypeInterface $entity_type, Connection $databa $this->database = $database; $this->uuidService = $uuid_service; - - // Check if the entity type supports IDs. - $this->idKey = $this->entityType->getKey('id'); - - // Check if the entity type supports UUIDs. - $this->uuidKey = $this->entityType->getKey('uuid'); } /** diff --git a/core/lib/Drupal/Core/Entity/EntityInterface.php b/core/lib/Drupal/Core/Entity/EntityInterface.php index 90e4699..bb1d459 100644 --- a/core/lib/Drupal/Core/Entity/EntityInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityInterface.php @@ -43,6 +43,14 @@ public function id(); public function language(); /** + * Returns the language code of the entity. + * + * @return string + * The language code. + */ + public function langcode(); + + /** * Returns whether the entity is new. * * Usually an entity is new if no ID exists for it yet. However, entities may diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index 5d10375..3621b9e 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -385,12 +385,12 @@ protected function buildBaseFieldDefinitions($entity_type_id) { // 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))); } - if (isset($base_field_definitions[$field_name]) && in_array($key, array('id', 'revision', 'uuid', 'bundle', 'langcode')) && $base_field_definitions[$field_name]->isTranslatable()) { + if (isset($base_field_definitions[$field_name]) && in_array($key, array('id', 'revision', 'uuid', 'bundle', 'language')) && $base_field_definitions[$field_name]->isTranslatable()) { throw new \LogicException(String::format('The @field field cannot be translatable 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 1befefc..a400c5f 100644 --- a/core/lib/Drupal/Core/Entity/EntityStorageBase.php +++ b/core/lib/Drupal/Core/Entity/EntityStorageBase.php @@ -6,6 +6,7 @@ */ namespace Drupal\Core\Entity; + use Drupal\Core\Entity\Query\QueryInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -60,6 +61,13 @@ protected $uuidKey; /** + * The name of the entity langcode property. + * + * @var string + */ + protected $languageKey; + + /** * Constructs an EntityStorageBase instance. * * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type @@ -70,6 +78,10 @@ public function __construct(EntityTypeInterface $entity_type) { $this->entityType = $entity_type; // Check if the entity type supports static caching of loaded entities. $this->cache = $this->entityType->isStaticallyCacheable(); + + $this->idKey = $this->entityType->getKey('id'); + $this->uuidKey = $this->entityType->getKey('uuid'); + $this->languageKey = $this->entityType->getKey('language'); } /** diff --git a/core/lib/Drupal/Core/Entity/EntityType.php b/core/lib/Drupal/Core/Entity/EntityType.php index de4411c..3bde57a 100644 --- a/core/lib/Drupal/Core/Entity/EntityType.php +++ b/core/lib/Drupal/Core/Entity/EntityType.php @@ -244,7 +244,11 @@ public function isFieldDataCacheable() { * {@inheritdoc} */ public function getKeys() { - return $this->entity_keys + array('revision' => '', 'bundle' => ''); + return $this->entity_keys + array( + 'revision' => '', + 'bundle' => '', + 'language' => '', + ); } /** diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Entity/Feed.php b/core/modules/aggregator/lib/Drupal/aggregator/Entity/Feed.php index daa3fba..5aaaba8 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Entity/Feed.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Entity/Feed.php @@ -10,6 +10,7 @@ use Drupal\Core\Entity\ContentEntityBase; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Field\FieldDefinition; +use Drupal\Core\Language\Language; use Symfony\Component\DependencyInjection\Container; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\aggregator\FeedInterface; @@ -38,8 +39,9 @@ * fieldable = TRUE, * entity_keys = { * "id" = "fid", - * "label" = "title", * "uuid" = "uuid", + * "language" = "langcode", + * "label" = "title", * } * ) */ diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Entity/Item.php b/core/modules/aggregator/lib/Drupal/aggregator/Entity/Item.php index f12ed40..e74b3b8 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Entity/Item.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Entity/Item.php @@ -27,6 +27,7 @@ * fieldable = TRUE, * entity_keys = { * "id" = "iid", + * "language" = "langcode", * "label" = "title", * } * ) diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Entity/CustomBlock.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Entity/CustomBlock.php index 041be76..2490515 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Entity/CustomBlock.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Entity/CustomBlock.php @@ -45,10 +45,11 @@ * translatable = TRUE, * entity_keys = { * "id" = "id", + * "uuid" = "uuid", * "revision" = "revision_id", + * "language" = "langcode", * "bundle" = "type", * "label" = "info", - * "uuid" = "uuid" * }, * bundle_entity_type = "custom_block_type" * ) diff --git a/core/modules/comment/lib/Drupal/comment/Entity/Comment.php b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php index 6dd943f..13a6c5c 100644 --- a/core/modules/comment/lib/Drupal/comment/Entity/Comment.php +++ b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php @@ -40,9 +40,10 @@ * translatable = TRUE, * entity_keys = { * "id" = "cid", + * "uuid" = "uuid", + * "language" = "langcode", * "bundle" = "field_id", * "label" = "subject", - * "uuid" = "uuid" * }, * links = { * "canonical" = "comment.permalink", diff --git a/core/modules/contact/lib/Drupal/contact/Entity/Message.php b/core/modules/contact/lib/Drupal/contact/Entity/Message.php index ff35420..666b2ef 100644 --- a/core/modules/contact/lib/Drupal/contact/Entity/Message.php +++ b/core/modules/contact/lib/Drupal/contact/Entity/Message.php @@ -26,7 +26,7 @@ * } * }, * entity_keys = { - * "bundle" = "category" + * "bundle" = "category", * }, * bundle_entity_type = "contact_category", * fieldable = TRUE, diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module index d7204a5..b584474 100644 --- a/core/modules/content_translation/content_translation.module +++ b/core/modules/content_translation/content_translation.module @@ -246,8 +246,19 @@ function _content_translation_menu_strip_loaders($path) { * The entity whose translation overview should be displayed. */ function content_translation_translate_access(EntityInterface $entity) { - return $entity instanceof ContentEntityInterface && empty($entity->getUntranslated()->language()->locked) && \Drupal::languageManager()->isMultilingual() && $entity->isTranslatable() && - (user_access('create content translations') || user_access('update content translations') || user_access('delete content translations')); + $account = \Drupal::currentUser(); + + $access = $entity instanceof ContentEntityInterface; + $access = $access && empty($entity->getUntranslated()->language()->locked); + $access = $access && \Drupal::languageManager()->isMultilingual(); + $access = $access && $entity->isTranslatable(); + $access = $access && ( + $account->hasPermission('create content translations') || + $account->hasPermission('update content translations') || + $account->hasPermission('delete content translations') + ); + + return $access; } /** diff --git a/core/modules/file/lib/Drupal/file/Entity/File.php b/core/modules/file/lib/Drupal/file/Entity/File.php index f6d9583..49c7271 100644 --- a/core/modules/file/lib/Drupal/file/Entity/File.php +++ b/core/modules/file/lib/Drupal/file/Entity/File.php @@ -28,8 +28,8 @@ * base_table = "file_managed", * entity_keys = { * "id" = "fid", + * "uuid" = "uuid", * "label" = "filename", - * "uuid" = "uuid" * } * ) */ diff --git a/core/modules/menu_link/lib/Drupal/menu_link/Entity/MenuLink.php b/core/modules/menu_link/lib/Drupal/menu_link/Entity/MenuLink.php index ebb28bf..6e20daa 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/Entity/MenuLink.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/Entity/MenuLink.php @@ -36,7 +36,8 @@ * "id" = "mlid", * "label" = "link_title", * "uuid" = "uuid", - * "bundle" = "bundle" + * "bundle" = "bundle", + * "language" = "langcode", * }, * ) */ diff --git a/core/modules/node/lib/Drupal/node/Entity/Node.php b/core/modules/node/lib/Drupal/node/Entity/Node.php index d5aea78..5d3232c 100644 --- a/core/modules/node/lib/Drupal/node/Entity/Node.php +++ b/core/modules/node/lib/Drupal/node/Entity/Node.php @@ -43,10 +43,12 @@ * translatable = TRUE, * entity_keys = { * "id" = "nid", + * "uuid" = "uuid", * "revision" = "vid", + * "language" = "langcode", + * "default_language" = "default_langcode", * "bundle" = "type", * "label" = "title", - * "uuid" = "uuid" * }, * bundle_entity_type = "node_type", * permission_granularity = "bundle", diff --git a/core/modules/shortcut/lib/Drupal/shortcut/Entity/Shortcut.php b/core/modules/shortcut/lib/Drupal/shortcut/Entity/Shortcut.php index 00d0dd3..bffcee8 100644 --- a/core/modules/shortcut/lib/Drupal/shortcut/Entity/Shortcut.php +++ b/core/modules/shortcut/lib/Drupal/shortcut/Entity/Shortcut.php @@ -35,8 +35,10 @@ * entity_keys = { * "id" = "id", * "uuid" = "uuid", + * "language" = "langcode", + * "default_language" = "default_langcode", * "bundle" = "shortcut_set", - * "label" = "title" + * "label" = "title", * }, * links = { * "delete-form" = "shortcut.link_delete", diff --git a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTest.php b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTest.php index 653d27a..1345e40 100644 --- a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTest.php +++ b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTest.php @@ -36,7 +36,8 @@ * "id" = "id", * "uuid" = "uuid", * "bundle" = "type", - * "label" = "name" + * "language" = "langcode", + * "label" = "name", * }, * links = { * "canonical" = "entity_test.render", diff --git a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestBaseFieldDisplay.php b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestBaseFieldDisplay.php index cddccc6..410ebd1 100644 --- a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestBaseFieldDisplay.php +++ b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestBaseFieldDisplay.php @@ -29,7 +29,7 @@ * "id" = "id", * "uuid" = "uuid", * "revision" = "revision_id", - * "bundle" = "type" + * "bundle" = "type", * }, * links = { * "edit-form" = "entity_test.edit_entity_test", diff --git a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestCache.php b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestCache.php index 8480d80..245ced4 100644 --- a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestCache.php +++ b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestCache.php @@ -26,7 +26,7 @@ * entity_keys = { * "id" = "id", * "uuid" = "uuid", - * "bundle" = "type" + * "bundle" = "type", * } * ) */ diff --git a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestLabel.php b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestLabel.php index 90a56a5..00fe8d0 100644 --- a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestLabel.php +++ b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestLabel.php @@ -21,7 +21,7 @@ * entity_keys = { * "id" = "id", * "label" = "name", - * "bundle" = "type" + * "bundle" = "type", * } * ) */ diff --git a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestLabelCallback.php b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestLabelCallback.php index 481711f..0088d70 100644 --- a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestLabelCallback.php +++ b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestLabelCallback.php @@ -20,7 +20,7 @@ * fieldable = TRUE, * entity_keys = { * "id" = "id", - * "bundle" = "type" + * "bundle" = "type", * } * ) */ diff --git a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestMul.php b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestMul.php index c38e806..4032769 100644 --- a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestMul.php +++ b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestMul.php @@ -32,8 +32,10 @@ * entity_keys = { * "id" = "id", * "uuid" = "uuid", + * "language" = "langcode", + * "default_language" = "default_langcode", * "bundle" = "type", - * "label" = "name" + * "label" = "name", * }, * links = { * "canonical" = "entity_test.edit_entity_test_mul", diff --git a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestMulRev.php b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestMulRev.php index 071ed67..6f9a348 100644 --- a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestMulRev.php +++ b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestMulRev.php @@ -34,7 +34,9 @@ * "id" = "id", * "uuid" = "uuid", * "revision" = "revision_id", - * "bundle" = "type" + * "language" = "langcode", + * "default_language" = "default_langcode", + * "bundle" = "type", * }, * links = { * "canonical" = "entity_test.edit_entity_test_mulrev", diff --git a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestNoLabel.php b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestNoLabel.php index 6dc35d4..4ca0b89 100644 --- a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestNoLabel.php +++ b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestNoLabel.php @@ -17,7 +17,7 @@ * base_table = "entity_test", * entity_keys = { * "id" = "id", - * "bundle" = "type" + * "bundle" = "type", * } * ) */ diff --git a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestRev.php b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestRev.php index 48f45bd..8e82900 100644 --- a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestRev.php +++ b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestRev.php @@ -31,6 +31,7 @@ * "id" = "id", * "uuid" = "uuid", * "revision" = "revision_id", + * "language" = "langcode", * "bundle" = "type", * "label" = "name", * }, diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Term.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Term.php index 4aef44b..69d25b5 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Term.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Term.php @@ -38,9 +38,10 @@ * translatable = TRUE, * entity_keys = { * "id" = "tid", + * "uuid" = "uuid", + * "language" = "langcode", * "bundle" = "vid", * "label" = "name", - * "uuid" = "uuid" * }, * bundle_entity_type = "taxonomy_vocabulary", * links = { diff --git a/core/modules/user/lib/Drupal/user/Entity/User.php b/core/modules/user/lib/Drupal/user/Entity/User.php index 83e2103..2d17cfe 100644 --- a/core/modules/user/lib/Drupal/user/Entity/User.php +++ b/core/modules/user/lib/Drupal/user/Entity/User.php @@ -41,7 +41,8 @@ * translatable = TRUE, * entity_keys = { * "id" = "uid", - * "uuid" = "uuid" + * "uuid" = "uuid", + * "language" = "langcode", * }, * links = { * "canonical" = "user.view", diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php index b16008c..9ad4bc0 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php @@ -544,7 +544,7 @@ public function testGetFieldDefinitionsWithCaching() { * @expectedException \LogicException */ public function testGetBaseFieldDefinitionsInvalidDefinition() { - $langcode_definition = $this->setUpEntityWithFieldDefinition(FALSE, 'langcode'); + $langcode_definition = $this->setUpEntityWithFieldDefinition(FALSE, 'langcode', 1, array('language' => 'langcode')); $langcode_definition->expects($this->once()) ->method('isTranslatable') ->will($this->returnValue(TRUE)); @@ -595,11 +595,17 @@ public function testGetFieldDefinitionsProvider() { * ModuleHandlerInterface::invokeAll() implementation. Defaults to FALSE. * @param string $field_definition_id * (optional) The ID to use for the field definition. Defaults to 'id'. + * @param int $base_field_definition_calls + * (optional) The number of times EntityInterface::baseFieldDefinitions() is + * expected to be called. Defaults to 1. + * @param array $entity_keys + * (optional) An array of entity keys for the mocked entity type. Defaults + * to an empty array. * * @return \Drupal\Core\Field\FieldDefinition|\PHPUnit_Framework_MockObject_MockObject * A field definition object. */ - protected function setUpEntityWithFieldDefinition($custom_invoke_all = FALSE, $field_definition_id = 'id', $base_field_definition_calls = 1) { + protected function setUpEntityWithFieldDefinition($custom_invoke_all = FALSE, $field_definition_id = 'id', $base_field_definition_calls = 1, $entity_keys = array()) { $entity_type = $this->getMock('Drupal\Core\Entity\EntityTypeInterface'); $entity = $this->getMock('Drupal\Tests\Core\Entity\TestContentEntityInterface'); $entity_class = get_class($entity); @@ -609,7 +615,7 @@ protected function setUpEntityWithFieldDefinition($custom_invoke_all = FALSE, $f ->will($this->returnValue($entity_class)); $entity_type->expects($this->any()) ->method('getKeys') - ->will($this->returnValue(array())); + ->will($this->returnValue($entity_keys)); $field_definition = $this->getMockBuilder('Drupal\Core\Field\FieldDefinition') ->disableOriginalConstructor() ->getMock(); diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php index 1cb561c..6984216 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php @@ -82,9 +82,9 @@ public function testHasKey($entity_keys, $expected) { */ 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' => '', 'language' => '')), + array(array('id' => 'id'), array('id' => 'id', 'revision' => '', 'bundle' => '', 'language' => '')), + array(array('bundle' => 'bundle'), array('bundle' => 'bundle', 'revision' => '', 'language' => '')), ); }