class EntitySchemaSubscriber implements EntityTypeListenerInterface, EventSubscriberInterface (View source)

Defines a class for listening to entity schema changes.

Traits

Helper methods for EntityTypeListenerInterface.

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

Properties

protected TranslationInterface $stringTranslation

The string translation service.

from  StringTranslationTrait
protected EntityDefinitionUpdateManagerInterface $entityDefinitionUpdateManager

The definition update manager.

protected EntityLastInstalledSchemaRepositoryInterface $entityLastInstalledSchemaRepository

The last installed schema definitions.

protected WorkspaceManagerInterface $workspaceManager

The workspace manager.

Methods

static array
getEntityTypeEvents()

Gets the subscribed events.

onEntityTypeEvent(EntityTypeEvent $event, string $event_name)

Listener method for any entity type definition event.

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.

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(EntityDefinitionUpdateManagerInterface $entityDefinitionUpdateManager, EntityLastInstalledSchemaRepositoryInterface $entityLastInstalledSchemaRepository, WorkspaceManagerInterface $workspace_manager)

Constructs a new EntitySchemaSubscriber.

static 
getSubscribedEvents()

{@inheritdoc}

addRevisionMetadataField(EntityTypeInterface $entity_type)

Adds the 'workspace' revision metadata field to an entity type.

getWorkspaceFieldDefinition()

Gets the base field definition for the 'workspace' revision metadata field.

Details

static array getEntityTypeEvents()

Gets the subscribed events.

Return Value

array

An array of subscribed event names.

See also

\Symfony\Component\EventDispatcher\EventSubscriberInterface::getSubscribedEvents()

onEntityTypeEvent(EntityTypeEvent $event, string $event_name)

Listener method for any entity type definition event.

Parameters

EntityTypeEvent $event

The field storage definition event object.

string $event_name

The event name.

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.

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(EntityDefinitionUpdateManagerInterface $entityDefinitionUpdateManager, EntityLastInstalledSchemaRepositoryInterface $entityLastInstalledSchemaRepository, WorkspaceManagerInterface $workspace_manager)

Constructs a new EntitySchemaSubscriber.

Parameters

EntityDefinitionUpdateManagerInterface $entityDefinitionUpdateManager

Definition update manager.

EntityLastInstalledSchemaRepositoryInterface $entityLastInstalledSchemaRepository

Last definitions.

WorkspaceManagerInterface $workspace_manager

The workspace manager.

static getSubscribedEvents()

{@inheritdoc}

protected addRevisionMetadataField(EntityTypeInterface $entity_type)

Adds the 'workspace' revision metadata field to an entity type.

Parameters

EntityTypeInterface $entity_type

The entity type that has been installed or updated.

protected BaseFieldDefinition getWorkspaceFieldDefinition()

Gets the base field definition for the 'workspace' revision metadata field.

Return Value

BaseFieldDefinition

The base field definition.