*/
protected $languageManager;
+ /**
+ * Whether this storage should use the temporary table mapping.
+ *
+ * @var bool
+ */
+ protected $temporary = FALSE;
+
/**
* {@inheritdoc}
*/
}
}
+ /**
+ * 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}
*/
// @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);
// 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.
/**
* {@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}
*/
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