class EntityDefinitionUpdateManager implements EntityDefinitionUpdateManagerInterface (View source)

Manages entity definition updates.

Traits

Wrapper methods for \Drupal\Core\StringTranslation\TranslationInterface.

Properties

protected TranslationInterface $stringTranslation

The string translation service.

from  StringTranslationTrait
protected EntityFieldManagerInterface $entityFieldManager

The entity field manager service.

protected EntityTypeListenerInterface $entityTypeListener

The entity type listener service.

protected EntityTypeManagerInterface $entityTypeManager

The entity type manager service.

protected FieldStorageDefinitionListenerInterface $fieldStorageDefinitionListener

The field storage definition listener service.

protected EntityLastInstalledSchemaRepositoryInterface $entityLastInstalledSchemaRepository

The last installed schema repository.

Methods

t(string $string, array $args = [], array $options = [])

Translates a string to the current language or to a given language.

formatPlural($count, $singular, $plural, array $args = [], array $options = [])

Formats a string containing a count of items.

getNumberOfPlurals($langcode = NULL)

Returns the number of plurals supported by a given language.

getStringTranslation()

Gets the string translation service.

$this
setStringTranslation(TranslationInterface $translation)

Sets the string translation service to use.

__construct(EntityTypeManagerInterface $entity_type_manager, EntityLastInstalledSchemaRepositoryInterface $entity_last_installed_schema_repository, EntityFieldManagerInterface $entity_field_manager, EntityTypeListenerInterface $entity_type_listener, FieldStorageDefinitionListenerInterface $field_storage_definition_listener)

Constructs a new EntityDefinitionUpdateManager.

bool
needsUpdates()

Checks if there are any definition updates that need to be applied.

array
getChangeSummary()

Gets a human readable summary of the detected changes.

getEntityType(string $entity_type_id)

Returns an entity type definition ready to be manipulated.

getEntityTypes()

Returns all the entity type definitions, ready to be manipulated.

installEntityType(EntityTypeInterface $entity_type)

Installs a new entity type definition.

updateEntityType(EntityTypeInterface $entity_type)

Applies any change performed to the passed entity type definition.

uninstallEntityType(EntityTypeInterface $entity_type)

Uninstalls an entity type definition.

installFieldableEntityType(EntityTypeInterface $entity_type, array $field_storage_definitions)

Installs a new fieldable entity type definition.

updateFieldableEntityType(EntityTypeInterface $entity_type, array $field_storage_definitions, array $sandbox = NULL)

Applies any change performed to a fieldable entity type definition.

installFieldStorageDefinition(string $name, string $entity_type_id, string $provider, FieldStorageDefinitionInterface $storage_definition)

Installs a new field storage definition.

getFieldStorageDefinition(string $name, string $entity_type_id)

Returns a field storage definition ready to be manipulated.

updateFieldStorageDefinition(FieldStorageDefinitionInterface $storage_definition)

Applies any change performed to the passed field storage definition.

uninstallFieldStorageDefinition(FieldStorageDefinitionInterface $storage_definition)

Uninstalls a field storage definition.

array
getChangeList()

Gets a list of changes to entity type and field storage definitions.

bool
requiresEntityStorageSchemaChanges(EntityTypeInterface $entity_type, EntityTypeInterface $original)

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

bool
requiresFieldStorageSchemaChanges(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original)

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

bool
requiresEntityDataMigration(EntityTypeInterface $entity_type, EntityTypeInterface $original)

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

clearCachedDefinitions()

Clears necessary caches to apply entity/field definition updates.

Details

protected TranslatableMarkup t(string $string, array $args = [], array $options = [])

Translates a string to the current language or to a given language.

See \Drupal\Core\StringTranslation\TranslatableMarkup::__construct() for important security information and usage guidelines.

In order for strings to be localized, make them available in one of the ways supported by the

Parameters

string $string

A string containing the English text to translate.

array $args

(optional) An associative array of replacements to make after translation. Based on the first character of the key, the value is escaped and/or themed. See \Drupal\Component\Render\FormattableMarkup::placeholderFormat() for details.

array $options

(optional) An associative array of additional options, with the following elements:

  • 'langcode' (defaults to the current language): A language code, to translate to a language other than what is used to display the page.
  • 'context' (defaults to the empty context): The context the source string belongs to. See the @link i18n Internationalization topic @endlink for more information about string contexts.

Return Value

TranslatableMarkup

An object that, when cast to a string, returns the translated string.

See also

FormattableMarkup::placeholderFormat
TranslatableMarkup::__construct

protected formatPlural($count, $singular, $plural, array $args = [], array $options = [])

Formats a string containing a count of items.

Parameters

$count
$singular
$plural
array $args
array $options

See also

TranslationInterface::formatPlural

protected getNumberOfPlurals($langcode = NULL)

Returns the number of plurals supported by a given language.

Parameters

$langcode

See also

PluralFormulaInterface::getNumberOfPlurals

protected TranslationInterface getStringTranslation()

Gets the string translation service.

Return Value

TranslationInterface

The string translation service.

$this setStringTranslation(TranslationInterface $translation)

Sets the string translation service to use.

Parameters

TranslationInterface $translation

The string translation service.

Return Value

$this

__construct(EntityTypeManagerInterface $entity_type_manager, EntityLastInstalledSchemaRepositoryInterface $entity_last_installed_schema_repository, EntityFieldManagerInterface $entity_field_manager, EntityTypeListenerInterface $entity_type_listener, FieldStorageDefinitionListenerInterface $field_storage_definition_listener)

Constructs a new EntityDefinitionUpdateManager.

Parameters

EntityTypeManagerInterface $entity_type_manager

The entity type manager service.

EntityLastInstalledSchemaRepositoryInterface $entity_last_installed_schema_repository

The last installed schema repository service.

EntityFieldManagerInterface $entity_field_manager

The entity field manager service.

EntityTypeListenerInterface $entity_type_listener

The entity type listener interface.

FieldStorageDefinitionListenerInterface $field_storage_definition_listener

The field storage definition listener service.

bool needsUpdates()

Checks if there are any definition updates that need to be applied.

Return Value

bool

TRUE if updates are needed.

array getChangeSummary()

Gets a human readable summary of the detected changes.

Return Value

array

An associative array keyed by entity type id. Each entry is an array of human-readable strings, each describing a change.

EntityTypeInterface|null getEntityType(string $entity_type_id)

Returns an entity type definition ready to be manipulated.

When needing to apply updates to existing entity type definitions, this method should always be used to retrieve a definition ready to be manipulated.

Parameters

string $entity_type_id

The entity type identifier.

Return Value

EntityTypeInterface|null

The entity type definition. Or NULL if not found.

EntityTypeInterface[] getEntityTypes()

Returns all the entity type definitions, ready to be manipulated.

When needing to apply updates to existing entity type definitions, this method should always be used to retrieve all the definitions ready to be manipulated.

Return Value

EntityTypeInterface[]

The last installed entity type definitions, keyed by the entity type ID.

installEntityType(EntityTypeInterface $entity_type)

Installs a new entity type definition.

Parameters

EntityTypeInterface $entity_type

The entity type definition.

updateEntityType(EntityTypeInterface $entity_type)

Applies any change performed to the passed entity type definition.

Parameters

EntityTypeInterface $entity_type

The entity type definition.

uninstallEntityType(EntityTypeInterface $entity_type)

Uninstalls an entity type definition.

Parameters

EntityTypeInterface $entity_type

The entity type definition.

installFieldableEntityType(EntityTypeInterface $entity_type, array $field_storage_definitions)

Installs a new fieldable entity type definition.

Parameters

EntityTypeInterface $entity_type

The entity type definition.

array $field_storage_definitions

The entity type's field storage definitions.

updateFieldableEntityType(EntityTypeInterface $entity_type, array $field_storage_definitions, array $sandbox = NULL)

Applies any change performed to a fieldable entity type definition.

Parameters

EntityTypeInterface $entity_type

The updated entity type definition.

array $field_storage_definitions

The updated field storage definitions, including possibly new ones.

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.

installFieldStorageDefinition(string $name, string $entity_type_id, string $provider, FieldStorageDefinitionInterface $storage_definition)

Installs a new field storage definition.

Parameters

string $name

The field storage definition name.

string $entity_type_id

The target entity type identifier.

string $provider

The name of the definition provider.

FieldStorageDefinitionInterface $storage_definition

The field storage definition.

FieldStorageDefinitionInterface getFieldStorageDefinition(string $name, string $entity_type_id)

Returns a field storage definition ready to be manipulated.

When needing to apply updates to existing field storage definitions, this method should always be used to retrieve a storage definition ready to be manipulated.

Parameters

string $name

The field name.

string $entity_type_id

The entity type identifier.

Return Value

FieldStorageDefinitionInterface

The field storage definition.

updateFieldStorageDefinition(FieldStorageDefinitionInterface $storage_definition)

Applies any change performed to the passed field storage definition.

Parameters

FieldStorageDefinitionInterface $storage_definition

The field storage definition.

uninstallFieldStorageDefinition(FieldStorageDefinitionInterface $storage_definition)

Uninstalls a field storage definition.

Parameters

FieldStorageDefinitionInterface $storage_definition

The field storage definition.

array getChangeList()

Gets a list of changes to entity type and field storage definitions.

Return Value

array

An associative array keyed by entity type ID of change descriptors. Every entry is an associative array with the following optional keys:

  • entity_type: a scalar having one value among:
    • EntityDefinitionUpdateManagerInterface::DEFINITION_CREATED
    • EntityDefinitionUpdateManagerInterface::DEFINITION_UPDATED
  • field_storage_definitions: an associative array keyed by field name of scalars having one value among:
    • EntityDefinitionUpdateManagerInterface::DEFINITION_CREATED
    • EntityDefinitionUpdateManagerInterface::DEFINITION_UPDATED
    • EntityDefinitionUpdateManagerInterface::DEFINITION_DELETED

protected 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.

protected 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.

protected bool requiresEntityDataMigration(EntityTypeInterface $entity_type, EntityTypeInterface $original)

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

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.

protected clearCachedDefinitions()

Clears necessary caches to apply entity/field definition updates.