interface DynamicallyFieldableEntityStorageSchemaInterface implements EntityStorageSchemaInterface, FieldStorageDefinitionListenerInterface (View source)

A storage schema that supports entity types with dynamic field definitions.

A storage schema that implements this interface can react to the entity type's field definitions changing, due to modules being installed or uninstalled, or via field UI, or via code changes to the entity class.

For example, configurable fields defined and exposed by field.module.

Methods

onEntityTypeCreate(EntityTypeInterface $entity_type)

Reacts to the creation of the entity type.

onFieldableEntityTypeCreate(EntityTypeInterface $entity_type, array $field_storage_definitions)

Reacts to the creation of the fieldable entity type.

onEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeInterface $original)

Reacts to the update of the entity type.

onFieldableEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeInterface $original, array $field_storage_definitions, array $original_field_storage_definitions, array $sandbox = NULL)

Reacts to the update of a fieldable entity type.

onEntityTypeDelete(EntityTypeInterface $entity_type)

Reacts to the deletion of the entity type.

bool
requiresEntityStorageSchemaChanges(EntityTypeInterface $entity_type, EntityTypeInterface $original)

Checks if the changes to the entity type requires storage schema changes.

bool
requiresEntityDataMigration(EntityTypeInterface $entity_type, EntityTypeInterface $original)

Checks if existing data would be lost if the schema changes were applied.

onFieldStorageDefinitionCreate(FieldStorageDefinitionInterface $storage_definition)

Reacts to the creation of a field storage definition.

onFieldStorageDefinitionUpdate(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original)

Reacts to the update of a field storage definition.

onFieldStorageDefinitionDelete(FieldStorageDefinitionInterface $storage_definition)

Reacts to the deletion of a field storage definition.

bool
requiresFieldStorageSchemaChanges(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original)

Checks if the changes to the storage definition requires schema changes.

bool
requiresFieldDataMigration(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original)

Checks if existing data would be lost if the schema changes were applied.

finalizePurge(FieldStorageDefinitionInterface $storage_definition)

Performs final cleanup after all data of a field has been purged.

Details

onEntityTypeCreate(EntityTypeInterface $entity_type)

Reacts to the creation of the entity type.

Parameters

EntityTypeInterface $entity_type

The entity type being created.

onFieldableEntityTypeCreate(EntityTypeInterface $entity_type, array $field_storage_definitions)

Reacts to the creation of the fieldable entity type.

Parameters

EntityTypeInterface $entity_type

The entity type being created.

array $field_storage_definitions

The entity type's field storage definitions.

onEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeInterface $original)

Reacts to the update of the entity type.

Parameters

EntityTypeInterface $entity_type

The updated entity type definition.

EntityTypeInterface $original

The original entity type definition.

onFieldableEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeInterface $original, array $field_storage_definitions, array $original_field_storage_definitions, array $sandbox = NULL)

Reacts to the update of a fieldable entity type.

Parameters

EntityTypeInterface $entity_type

The updated entity type definition.

EntityTypeInterface $original

The original entity type definition.

array $field_storage_definitions

The updated field storage definitions, including possibly new ones.

array $original_field_storage_definitions

The original field storage definitions.

array $sandbox

(optional) A sandbox array provided by a hook_update_N() implementation or a Batch API callback. If the entity schema update requires a data migration, this parameter is mandatory. Defaults to NULL.

onEntityTypeDelete(EntityTypeInterface $entity_type)

Reacts to the deletion of the entity type.

Parameters

EntityTypeInterface $entity_type

The entity type being deleted.

bool requiresEntityStorageSchemaChanges(EntityTypeInterface $entity_type, EntityTypeInterface $original)

Checks if the changes to the entity type requires storage schema changes.

Parameters

EntityTypeInterface $entity_type

The updated entity type definition.

EntityTypeInterface $original

The original entity type definition.

Return Value

bool

TRUE if storage schema changes are required, FALSE otherwise.

bool requiresEntityDataMigration(EntityTypeInterface $entity_type, EntityTypeInterface $original)

Checks if existing data would be lost if the schema changes were applied.

If there are no schema changes needed, then no data needs to be migrated, but it is not the responsibility of this function to recheck what requiresEntityStorageSchemaChanges() checks. Rather, the meaning of what this function returns when requiresEntityStorageSchemaChanges() returns FALSE is undefined. Callers are expected to only call this function when requiresEntityStorageSchemaChanges() is TRUE.

This function can return FALSE if any of these conditions apply:

  • There are no existing entities for the entity type.
  • There are existing entities, but the schema changes can be applied without losing their data (e.g., if the schema changes can be performed by altering tables rather than dropping and recreating them).
  • The only entity data that would be lost are ones that are not valid for the new definition (e.g., if changing an entity type from revisionable to non-revisionable, then it's okay to drop data for the non-default revision).

When this function returns FALSE, site administrators will be unable to perform an automated update, and will instead need to perform a site migration or invoke some custom update process.

Parameters

EntityTypeInterface $entity_type

The updated entity type definition.

EntityTypeInterface $original

The original entity type definition.

Return Value

bool

TRUE if data migration is required, FALSE otherwise.

See also

\Drupal\Core\Entity\Schema\self::requiresEntityStorageSchemaChanges()

onFieldStorageDefinitionCreate(FieldStorageDefinitionInterface $storage_definition)

Reacts to the creation of a field storage definition.

Parameters

FieldStorageDefinitionInterface $storage_definition

The definition being created.

onFieldStorageDefinitionUpdate(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original)

Reacts to the update of a field storage definition.

Parameters

FieldStorageDefinitionInterface $storage_definition

The field being updated.

FieldStorageDefinitionInterface $original

The original storage definition; i.e., the definition before the update.

Exceptions

FieldStorageDefinitionUpdateForbiddenException

onFieldStorageDefinitionDelete(FieldStorageDefinitionInterface $storage_definition)

Reacts to the deletion of a field storage definition.

Parameters

FieldStorageDefinitionInterface $storage_definition

The field being deleted.

bool requiresFieldStorageSchemaChanges(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original)

Checks if the changes to the storage definition requires schema changes.

Parameters

FieldStorageDefinitionInterface $storage_definition

The updated field storage definition.

FieldStorageDefinitionInterface $original

The original field storage definition.

Return Value

bool

TRUE if storage schema changes are required, FALSE otherwise.

bool requiresFieldDataMigration(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original)

Checks if existing data would be lost if the schema changes were applied.

If there are no schema changes needed, then no data needs to be migrated, but it is not the responsibility of this function to recheck what requiresFieldStorageSchemaChanges() checks. Rather, the meaning of what this function returns when requiresFieldStorageSchemaChanges() returns FALSE is undefined. Callers are expected to only call this function when requiresFieldStorageSchemaChanges() is TRUE.

This function can return FALSE if any of these conditions apply:

  • There are no existing entities for the entity type to which this field is attached.
  • There are existing entities, but none with existing values for this field.
  • There are existing field values, but the schema changes can be applied without losing them (e.g., if the schema changes can be performed by altering tables rather than dropping and recreating them).
  • The only field values that would be lost are ones that are not valid for the new definition (e.g., if changing a field from revisionable to non-revisionable, then it's okay to drop data for the non-default revision).

When this function returns FALSE, site administrators will be unable to perform an automated update, and will instead need to perform a site migration or invoke some custom update process.

Parameters

FieldStorageDefinitionInterface $storage_definition

The updated field storage definition.

FieldStorageDefinitionInterface $original

The original field storage definition.

Return Value

bool

TRUE if data migration is required, FALSE otherwise.

See also

\Drupal\Core\Entity\Schema\self::requiresFieldStorageSchemaChanges()

finalizePurge(FieldStorageDefinitionInterface $storage_definition)

Performs final cleanup after all data of a field has been purged.

Parameters

FieldStorageDefinitionInterface $storage_definition

The field being purged.