class SqlContentEntityStorageSchemaConverter (View source)

deprecated in drupal:8.7.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface::updateFieldableEntityType() instead.

Defines a schema converter for entity types with existing data.

Properties

protected string $entityTypeId

The entity type ID this schema converter is responsible for.

protected EntityTypeManagerInterface $entityTypeManager

The entity type manager.

protected EntityDefinitionUpdateManagerInterface $entityDefinitionUpdateManager

The entity definition update manager service.

Methods

__construct(string $entity_type_id, EntityTypeManagerInterface $entity_type_manager, EntityDefinitionUpdateManagerInterface $entity_definition_update_manager)

SqlContentEntityStorageSchemaConverter constructor.

convertToRevisionable(array $sandbox, array $fields_to_update = [])

Converts an entity type with existing data to be revisionable.

Details

__construct(string $entity_type_id, EntityTypeManagerInterface $entity_type_manager, EntityDefinitionUpdateManagerInterface $entity_definition_update_manager)

SqlContentEntityStorageSchemaConverter constructor.

Parameters

string $entity_type_id

The ID of the entity type.

EntityTypeManagerInterface $entity_type_manager

The entity type manager.

EntityDefinitionUpdateManagerInterface $entity_definition_update_manager

Entity definition update manager service.

convertToRevisionable(array $sandbox, array $fields_to_update = [])

Converts an entity type with existing data to be revisionable.

This process does the following tasks:

  • creates the schema from scratch with the new revisionable entity type definition (i.e. the current definition of the entity type from code) using temporary table names;
  • loads the initial entity data by using the last installed entity and field storage definitions;
  • saves the entity data to the temporary tables;
  • at the end of the process:
    • deletes the original tables and replaces them with the temporary ones that hold the new (revisionable) entity data;
    • updates the installed entity schema data;
    • updates the entity type definition in order to trigger the \Drupal\Core\Entity\EntityTypeEvents::UPDATE event;
    • updates the field storage definitions in order to mark the revisionable ones as such.

In case of an error during the entity save process, the temporary tables are deleted and the original entity type and field storage definitions are restored.

Parameters

array $sandbox

The sandbox array from a hook_update_N() implementation.

array $fields_to_update

(optional) An array of field names that should be converted to be revisionable. Note that the 'langcode' field, if present, is updated automatically. Defaults to an empty array.

Exceptions

Exception