X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Flib%2FDrupal%2FCore%2FEntity%2FSql%2FSqlContentEntityStorage.php;fp=web%2Fcore%2Flib%2FDrupal%2FCore%2FEntity%2FSql%2FSqlContentEntityStorage.php;h=22238d4bf50548377308ab9e840598354b599ee1;hp=a13a4b2d17fbe2cd27a56b4951f2decebd062b49;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hpb=aea91e65e895364e460983b890e295aa5d5540a5 diff --git a/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php b/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php index a13a4b2d1..22238d4bf 100644 --- a/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php +++ b/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php @@ -117,6 +117,13 @@ class SqlContentEntityStorage extends ContentEntityStorageBase implements SqlEnt */ protected $languageManager; + /** + * Whether this storage should use the temporary table mapping. + * + * @var bool + */ + protected $temporary = FALSE; + /** * {@inheritdoc} */ @@ -266,6 +273,31 @@ class SqlContentEntityStorage extends ContentEntityStorageBase implements SqlEnt } } + /** + * Sets the wrapped table mapping definition. + * + * @param \Drupal\Core\Entity\Sql\TableMappingInterface $table_mapping + * The table mapping. + * + * @internal Only to be used internally by Entity API. Expected to be removed + * by https://www.drupal.org/node/2554235. + */ + public function setTableMapping(TableMappingInterface $table_mapping) { + $this->tableMapping = $table_mapping; + } + + /** + * Changes the temporary state of the storage. + * + * @param bool $temporary + * Whether to use a temporary table mapping or not. + * + * @internal Only to be used internally by Entity API. + */ + public function setTemporary($temporary) { + $this->temporary = $temporary; + } + /** * {@inheritdoc} */ @@ -279,8 +311,10 @@ class SqlContentEntityStorage extends ContentEntityStorageBase implements SqlEnt // @todo Clean-up this in https://www.drupal.org/node/2274017 so we can // easily instantiate a new table mapping whenever needed. if (!isset($this->tableMapping) || $storage_definitions) { + $table_mapping_class = $this->temporary ? TemporaryTableMapping::class : DefaultTableMapping::class; $definitions = $storage_definitions ?: $this->entityManager->getFieldStorageDefinitions($this->entityTypeId); - $table_mapping = new DefaultTableMapping($this->entityType, $definitions); + /** @var \Drupal\Core\Entity\Sql\DefaultTableMapping|\Drupal\Core\Entity\Sql\TemporaryTableMapping $table_mapping */ + $table_mapping = new $table_mapping_class($this->entityType, $definitions); $shared_table_definitions = array_filter($definitions, function (FieldStorageDefinitionInterface $definition) use ($table_mapping) { return $table_mapping->allowsSharedTableStorage($definition); @@ -294,17 +328,11 @@ class SqlContentEntityStorage extends ContentEntityStorageBase implements SqlEnt // Make sure the key fields come first in the list of fields. $all_fields = array_merge($key_fields, array_diff($all_fields, $key_fields)); - // Nodes have all three of these fields, while custom blocks only have - // log. - // @todo Provide automatic definitions for revision metadata fields in - // https://www.drupal.org/node/2248983. - $revision_metadata_fields = array_intersect([ - 'revision_timestamp', - 'revision_uid', - 'revision_log', - ], $all_fields); - + // If the entity is revisionable, gather the fields that need to be put + // in the revision table. $revisionable = $this->entityType->isRevisionable(); + $revision_metadata_fields = $revisionable ? array_values($this->entityType->getRevisionMetadataKeys()) : []; + $translatable = $this->entityType->isTranslatable(); if (!$revisionable && !$translatable) { // The base layout stores all the base field values in the base table. @@ -1512,12 +1540,12 @@ class SqlContentEntityStorage extends ContentEntityStorageBase implements SqlEnt /** * {@inheritdoc} */ - public function onBundleCreate($bundle, $entity_type_id) { } + public function onBundleCreate($bundle, $entity_type_id) {} /** * {@inheritdoc} */ - public function onBundleDelete($bundle, $entity_type_id) { } + public function onBundleDelete($bundle, $entity_type_id) {} /** * {@inheritdoc} @@ -1699,7 +1727,7 @@ class SqlContentEntityStorage extends ContentEntityStorageBase implements SqlEnt */ protected function storageDefinitionIsDeleted(FieldStorageDefinitionInterface $storage_definition) { // Configurable fields are marked for deletion. - if ($storage_definition instanceOf FieldStorageConfigInterface) { + if ($storage_definition instanceof FieldStorageConfigInterface) { return $storage_definition->isDeleted(); } // For non configurable fields check whether they are still in the last