summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorFrancesco Placella2019-03-25 09:45:52 (GMT)
committerFrancesco Placella2019-03-25 09:45:52 (GMT)
commita54e207f611d203d08992bed0c466c01c1954ec4 (patch)
treecbf6b823c158f3aa0552b25c10654bbc64d18b29 /core
parent8d1a7d7c861f076a59ddcd82aa08654a7e35a004 (diff)
Issue #3042993 by amateescu, tedbow: Translatable and revisonable installed entity type definitions are missing the 'revision_translation_affected' entity keyHEAD8.8.x
Diffstat (limited to 'core')
-rw-r--r--core/modules/system/system.install32
-rw-r--r--core/modules/system/tests/src/Functional/Update/EntityUpdateAddRevisionTranslationAffectedTest.php5
2 files changed, 37 insertions, 0 deletions
diff --git a/core/modules/system/system.install b/core/modules/system/system.install
index 960bb7d..d810a24 100644
--- a/core/modules/system/system.install
+++ b/core/modules/system/system.install
@@ -2247,3 +2247,35 @@ function system_update_8701() {
// The system.theme.data key is no longer used in Drupal 8.7.x.
\Drupal::state()->delete('system.theme.data');
}
+
+/**
+ * Add the 'revision_translation_affected' entity key.
+ */
+function system_update_8702() {
+ $entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager();
+
+ // Get a list of revisionable and translatable entity types.
+ /** @var \Drupal\Core\Entity\EntityTypeInterface[] $last_installed_definitions */
+ $last_installed_definitions = array_filter($entity_definition_update_manager->getEntityTypes(), function (EntityTypeInterface $entity_type) {
+ return $entity_type->isRevisionable() && $entity_type->isTranslatable();
+ });
+
+ // Ensure that we don't use the cached in-code definitions to support sites
+ // that might be updating from 8.3.x straight to 8.7.x.
+ \Drupal::entityTypeManager()->useCaches(FALSE);
+ $live_definitions = \Drupal::entityTypeManager()->getDefinitions();
+
+ // Update the 'revision_translation_affected' entity key of the last installed
+ // definitions to use the value of the live (in-code) entity type definitions
+ // in cases when the key has not been populated yet.
+ foreach ($last_installed_definitions as $entity_type_id => $entity_type) {
+ $revision_translation_affected_key = $live_definitions[$entity_type_id]->getKey('revision_translation_affected');
+ if (!$entity_type->hasKey('revision_translation_affected') && !empty($revision_translation_affected_key) && $entity_definition_update_manager->getFieldStorageDefinition($revision_translation_affected_key, $entity_type_id)) {
+ $entity_keys = $entity_type->getKeys();
+ $entity_keys['revision_translation_affected'] = $revision_translation_affected_key;
+ $entity_type->set('entity_keys', $entity_keys);
+ $entity_definition_update_manager->updateEntityType($entity_type);
+ }
+ }
+ \Drupal::entityTypeManager()->useCaches(TRUE);
+}
diff --git a/core/modules/system/tests/src/Functional/Update/EntityUpdateAddRevisionTranslationAffectedTest.php b/core/modules/system/tests/src/Functional/Update/EntityUpdateAddRevisionTranslationAffectedTest.php
index b6c4fd0..a2ba387 100644
--- a/core/modules/system/tests/src/Functional/Update/EntityUpdateAddRevisionTranslationAffectedTest.php
+++ b/core/modules/system/tests/src/Functional/Update/EntityUpdateAddRevisionTranslationAffectedTest.php
@@ -56,6 +56,7 @@ class EntityUpdateAddRevisionTranslationAffectedTest extends UpdatePathTestBase
* Tests the addition of the 'revision_translation_affected' base field.
*
* @see system_update_8402()
+ * @see system_update_8702()
*/
public function testAddingTheRevisionTranslationAffectedField() {
// Make the entity type revisionable and translatable prior to running the
@@ -74,6 +75,10 @@ class EntityUpdateAddRevisionTranslationAffectedTest extends UpdatePathTestBase
$field_storage_definitions = \Drupal::service('entity.last_installed_schema.repository')->getLastInstalledFieldStorageDefinitions('entity_test_update');
$this->assertTrue(isset($field_storage_definitions['revision_translation_affected']));
+ // Check that the entity type has the 'revision_translation_affected' key.
+ $entity_type = \Drupal::entityDefinitionUpdateManager()->getEntityType('entity_test_update');
+ $this->assertEquals('revision_translation_affected', $entity_type->getKey('revision_translation_affected'));
+
// Check that the correct initial value was set when the field was
// installed.
$entity = \Drupal::entityTypeManager()->getStorage('entity_test_update')->load(1);