Security update for Core, with self-updated composer
[yaffs-website] / web / core / lib / Drupal / Core / Field / FieldStorageDefinitionListener.php
index bb17fe6bf0d1016de5ab2c1b9b642fb1f1a0dd70..154e485ecbd5a6cd8be9912891eff1f161af09aa 100644 (file)
@@ -5,6 +5,7 @@ namespace Drupal\Core\Field;
 use Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface;
 use Drupal\Core\Entity\EntityFieldManagerInterface;
 use Drupal\Core\Entity\EntityTypeManagerInterface;
+use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
 use Symfony\Component\EventDispatcher\EventDispatcherInterface;
 
 /**
@@ -69,7 +70,17 @@ class FieldStorageDefinitionListener implements FieldStorageDefinitionListenerIn
 
     // @todo Forward this to all interested handlers, not only storage, once
     //   iterating handlers is possible: https://www.drupal.org/node/2332857.
-    $storage = $this->entityTypeManager->getStorage($entity_type_id);
+    $storage = clone $this->entityTypeManager->getStorage($entity_type_id);
+
+    // Entity type definition updates can change the schema by adding or
+    // removing entity tables (for example when switching an entity type from
+    // non-revisionable to revisionable), so CRUD operations on a field storage
+    // definition need to use the last installed entity type schema.
+    if ($storage instanceof SqlContentEntityStorage
+       && ($last_installed_entity_type = $this->entityLastInstalledSchemaRepository->getLastInstalledDefinition($entity_type_id))) {
+      $storage->setEntityType($last_installed_entity_type);
+    }
+
     if ($storage instanceof FieldStorageDefinitionListenerInterface) {
       $storage->onFieldStorageDefinitionCreate($storage_definition);
     }
@@ -88,7 +99,17 @@ class FieldStorageDefinitionListener implements FieldStorageDefinitionListenerIn
 
     // @todo Forward this to all interested handlers, not only storage, once
     //   iterating handlers is possible: https://www.drupal.org/node/2332857.
-    $storage = $this->entityTypeManager->getStorage($entity_type_id);
+    $storage = clone $this->entityTypeManager->getStorage($entity_type_id);
+
+    // Entity type definition updates can change the schema by adding or
+    // removing entity tables (for example when switching an entity type from
+    // non-revisionable to revisionable), so CRUD operations on a field storage
+    // definition need to use the last installed entity type schema.
+    if ($storage instanceof SqlContentEntityStorage
+       && ($last_installed_entity_type = $this->entityLastInstalledSchemaRepository->getLastInstalledDefinition($entity_type_id))) {
+      $storage->setEntityType($last_installed_entity_type);
+    }
+
     if ($storage instanceof FieldStorageDefinitionListenerInterface) {
       $storage->onFieldStorageDefinitionUpdate($storage_definition, $original);
     }
@@ -107,7 +128,17 @@ class FieldStorageDefinitionListener implements FieldStorageDefinitionListenerIn
 
     // @todo Forward this to all interested handlers, not only storage, once
     //   iterating handlers is possible: https://www.drupal.org/node/2332857.
-    $storage = $this->entityTypeManager->getStorage($entity_type_id);
+    $storage = clone $this->entityTypeManager->getStorage($entity_type_id);
+
+    // Entity type definition updates can change the schema by adding or
+    // removing entity tables (for example when switching an entity type from
+    // non-revisionable to revisionable), so CRUD operations on a field storage
+    // definition need to use the last installed entity type schema.
+    if ($storage instanceof SqlContentEntityStorage
+       && ($last_installed_entity_type = $this->entityLastInstalledSchemaRepository->getLastInstalledDefinition($entity_type_id))) {
+      $storage->setEntityType($last_installed_entity_type);
+    }
+
     if ($storage instanceof FieldStorageDefinitionListenerInterface) {
       $storage->onFieldStorageDefinitionDelete($storage_definition);
     }