class PathAliasStorageSchema extends SqlContentEntityStorageSchema (View source)

Defines the path_alias schema handler.

Traits

Provides dependency injection friendly methods for serialization.

Helper methods for EntityTypeListenerInterface.

Properties

protected array $_serviceIds

An array of service IDs keyed by property name used for serialization.

from  DependencySerializationTrait
protected array $_entityStorages

An array of entity type IDs keyed by the property name of their storages.

from  DependencySerializationTrait
protected EntityTypeManagerInterface $entityTypeManager

The entity type manager.

from  SqlContentEntityStorageSchema
protected EntityFieldManagerInterface $entityFieldManager

The entity field manager service.

from  SqlContentEntityStorageSchema
protected ContentEntityTypeInterface $entityType

The entity type this schema builder is responsible for.

from  SqlContentEntityStorageSchema
protected FieldStorageDefinitionInterface[] $fieldStorageDefinitions

The storage field definitions for this entity type.

from  SqlContentEntityStorageSchema
protected SqlContentEntityStorage $storage

The storage object for the given entity type.

from  SqlContentEntityStorageSchema
protected array $schema

A static cache of the generated schema array.

from  SqlContentEntityStorageSchema
protected Connection $database

The database connection to be used.

from  SqlContentEntityStorageSchema
protected KeyValueStoreInterface $installedStorageSchema

The key-value collection for tracking installed storage schema.

from  SqlContentEntityStorageSchema
protected KeyValueStoreInterface $updateBackupRepository

The key-value collection for tracking entity update backup repository.

from  SqlContentEntityStorageSchema
protected DeletedFieldsRepositoryInterface $deletedFieldsRepository

The deleted fields repository.

from  SqlContentEntityStorageSchema

Methods

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

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

{@inheritdoc}

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

Allows subscribers to prepare their schema before data copying.

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

Allows subscribers to do any cleanup necessary after data copying.

copyData(EntityTypeInterface $entity_type, EntityTypeInterface $original, array $field_storage_definitions, array $original_field_storage_definitions, array $sandbox)

Copies entity data from the original storage to the temporary one.

handleEntityTypeSchemaUpdateExceptionOnDataCopy(EntityTypeInterface $entity_type, EntityTypeInterface $original, array $sandbox)

Handles the case when an error occurs during the data copying step.

__construct(EntityTypeManagerInterface $entity_type_manager, ContentEntityTypeInterface $entity_type, SqlContentEntityStorage $storage, Connection $database, EntityFieldManagerInterface $entity_field_manager)

Constructs a SqlContentEntityStorageSchema.

installedStorageSchema()

Gets the keyvalue collection for tracking the installed schema.

updateBackupRepository()

Gets the key/value collection for tracking the entity update backups.

getTableMapping(EntityTypeInterface $entity_type, array $storage_definitions = NULL)

Refreshes the table mapping with updated definitions.

bool
requiresEntityStorageSchemaChanges(EntityTypeInterface $entity_type, EntityTypeInterface $original)

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

bool
hasSharedTableStructureChange(EntityTypeInterface $entity_type, EntityTypeInterface $original)

Detects whether there is a change in the shared table structure.

bool
hasSharedTableNameChanges(EntityTypeInterface $entity_type, EntityTypeInterface $original)

Detects whether any table name got renamed in an entity type update.

bool
requiresFieldStorageSchemaChanges(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original)

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

array
getSchemaFromStorageDefinition(FieldStorageDefinitionInterface $storage_definition)

Gets the schema data for the given field storage definition.

bool
requiresEntityDataMigration(EntityTypeInterface $entity_type, EntityTypeInterface $original)

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

bool
requiresFieldDataMigration(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original)

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

onEntityTypeCreate(EntityTypeInterface $entity_type)

Reacts to the creation of the entity type.

onEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeInterface $original)

Reacts to the update of the entity type.

onEntityTypeDelete(EntityTypeInterface $entity_type)

Reacts to the deletion of the entity type.

onFieldableEntityTypeCreate(EntityTypeInterface $entity_type, array $field_storage_definitions)

Reacts to the creation of the fieldable entity type.

static string
getTemporaryTableMappingPrefix(EntityTypeInterface $entity_type, array $field_storage_definitions, string $first_prefix_part = 'tmp_')

Gets a string to be used as a prefix for a temporary table mapping object.

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.

finalizePurge(FieldStorageDefinitionInterface $storage_definition)

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

getSelectQueryForFieldStorageDeletion(string $table_name, array $shared_table_field_columns, array $dedicated_table_field_columns, string $base_table = NULL)

Returns a SELECT query suitable for inserting data into a dedicated table.

bool
checkEntityType(EntityTypeInterface $entity_type)

Checks that we are dealing with the correct entity type.

array
getEntitySchema(ContentEntityTypeInterface $entity_type, bool $reset = FALSE)

Gets the entity schema for the specified entity type.

array
getEntitySchemaTables(TableMappingInterface $table_mapping)

Gets a list of entity type tables.

array
getEntitySchemaData(ContentEntityTypeInterface $entity_type, array $schema)

Gets entity schema definitions for index and key definitions.

array
getFieldIndexes(string $field_name, array $field_schema, array $column_mapping)

Gets an index schema array for a given field.

array
getFieldUniqueKeys(string $field_name, array $field_schema, array $column_mapping)

Gets a unique key schema array for a given field.

array
getFieldSchemaData(string $field_name, array $field_schema, array $column_mapping, string $schema_key)

Gets field schema data for the given key.

string
getFieldSchemaIdentifierName(string $entity_type_id, string $field_name, string|null $key = NULL)

Generates a safe schema identifier (name of an index, column name etc.).

array
getFieldForeignKeys(string $field_name, array $field_schema, array $column_mapping)

Gets field foreign keys.

array
loadEntitySchemaData(EntityTypeInterface $entity_type)

Loads stored schema data for the given entity type definition.

saveEntitySchemaData(EntityTypeInterface $entity_type, array $schema)

Stores schema data for the given entity type definition.

deleteEntitySchemaData(EntityTypeInterface $entity_type)

Deletes schema data for the given entity type definition.

array
loadFieldSchemaData(FieldStorageDefinitionInterface $storage_definition)

Loads stored schema data for the given field storage definition.

saveFieldSchemaData(FieldStorageDefinitionInterface $storage_definition, array $schema)

Stores schema data for the given field storage definition.

deleteFieldSchemaData(FieldStorageDefinitionInterface $storage_definition)

Deletes schema data for the given field storage definition.

array
initializeBaseTable(ContentEntityTypeInterface $entity_type)

Initializes common information for a base table.

array
initializeRevisionTable(ContentEntityTypeInterface $entity_type)

Initializes common information for a revision table.

array
initializeDataTable(ContentEntityTypeInterface $entity_type)

Initializes common information for a data table.

array
initializeRevisionDataTable(ContentEntityTypeInterface $entity_type)

Initializes common information for a revision data table.

addTableDefaults($schema)

Adds defaults to a table schema definition.

array
processDataTable(ContentEntityTypeInterface $entity_type, array $schema)

Processes the gathered schema for a base table.

array
processRevisionDataTable(ContentEntityTypeInterface $entity_type, array $schema)

Processes the gathered schema for a base table.

processIdentifierSchema(array $schema, string $key)

Processes the specified entity key.

processFieldStorageSchema(array $field_storage_schema)

Processes the schema for a field storage definition.

performFieldSchemaOperation(string $operation, FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original = NULL)

Performs the specified operation on a field.

createDedicatedTableSchema(FieldStorageDefinitionInterface $storage_definition, bool $only_save = FALSE)

Creates the schema for a field stored in a dedicated table.

createSharedTableSchema(FieldStorageDefinitionInterface $storage_definition, bool $only_save = FALSE)

Creates the schema for a field stored in a shared table.

deleteDedicatedTableSchema(FieldStorageDefinitionInterface $storage_definition)

Deletes the schema for a field stored in a dedicated table.

deleteSharedTableSchema(FieldStorageDefinitionInterface $storage_definition)

Deletes the schema for a field stored in a shared table.

updateDedicatedTableSchema(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original)

Updates the schema for a field stored in a shared table.

updateSharedTableSchema(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original)

Updates the schema for a field stored in a shared table.

createEntitySchemaIndexes(array $entity_schema, FieldStorageDefinitionInterface $storage_definition = NULL)

Creates the specified entity schema indexes and keys.

deleteEntitySchemaIndexes(array $entity_schema_data, FieldStorageDefinitionInterface $storage_definition = NULL)

Deletes the specified entity schema indexes and keys.

bool
hasNullFieldPropertyData(string $table_name, string $column_name)

Checks whether a field property has NULL values.

array
getSharedTableFieldSchema(FieldStorageDefinitionInterface $storage_definition, string $table_name, array $column_mapping)

Gets the schema for a single field definition.

addSharedTableFieldIndex(FieldStorageDefinitionInterface $storage_definition, array $schema, bool $not_null = FALSE, int $size = NULL)

Adds an index for the specified field to the given schema definition.

addSharedTableFieldUniqueKey(FieldStorageDefinitionInterface $storage_definition, array $schema)

Adds a unique key for the specified field to the given schema definition.

addSharedTableFieldForeignKey(FieldStorageDefinitionInterface $storage_definition, array $schema, string $foreign_table, string $foreign_column)

Adds a foreign key for the specified field to the given schema definition.

array
getDedicatedTableSchema(FieldStorageDefinitionInterface $storage_definition, ContentEntityTypeInterface $entity_type = NULL)

Gets the SQL schema for a dedicated table.

string
getEntityIndexName(ContentEntityTypeInterface $entity_type, string $index)

Gets the name to be used for the given entity index.

string
getFieldIndexName(FieldStorageDefinitionInterface $storage_definition, string $index)

Generates an index name for a field data table.

bool
isTableEmpty(string $table_name)

Checks whether a database table is non-existent or empty.

bool
hasColumnChanges(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original)

Compares schemas to check for changes in the column definitions.

string[]
getColumnSchemaRelevantKeys()

Returns a list of column schema keys affecting data storage.

addIndex(string $table, string $name, array $specifier, array $schema)

Creates an index, dropping it if already existing.

addUniqueKey(string $table, string $name, array $specifier)

Creates a unique key, dropping it if already existing.

static mixed
castValue(array $info, mixed $value)

Typecasts values to proper datatypes.

Details

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

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

{@inheritdoc}

Parameters

EntityTypeInterface $entity_type
EntityTypeInterface $original
array $field_storage_definitions
array $original_field_storage_definitions
array $sandbox

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

Allows subscribers to prepare their schema before data copying.

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.

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

Allows subscribers to do any cleanup necessary after data copying.

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.

protected copyData(EntityTypeInterface $entity_type, EntityTypeInterface $original, array $field_storage_definitions, array $original_field_storage_definitions, array $sandbox)

Copies entity data from the original storage to the temporary one.

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

The sandbox array from a hook_update_N() implementation.

protected handleEntityTypeSchemaUpdateExceptionOnDataCopy(EntityTypeInterface $entity_type, EntityTypeInterface $original, array $sandbox)

Handles the case when an error occurs during the data copying step.

Parameters

EntityTypeInterface $entity_type

The updated entity type definition.

EntityTypeInterface $original

The original entity type definition.

array $sandbox

The sandbox array from a hook_update_N() implementation.

__construct(EntityTypeManagerInterface $entity_type_manager, ContentEntityTypeInterface $entity_type, SqlContentEntityStorage $storage, Connection $database, EntityFieldManagerInterface $entity_field_manager)

Constructs a SqlContentEntityStorageSchema.

Parameters

EntityTypeManagerInterface $entity_type_manager

The entity type manager.

ContentEntityTypeInterface $entity_type

The entity type.

SqlContentEntityStorage $storage

The storage of the entity type. This must be an SQL-based storage.

Connection $database

The database connection to be used.

EntityFieldManagerInterface $entity_field_manager

The entity field manager.

protected KeyValueStoreInterface installedStorageSchema()

Gets the keyvalue collection for tracking the installed schema.

Inject this dependency in the constructor once this class can be instantiated as a regular entity handler: https://www.drupal.org/node/2332857.

Return Value

KeyValueStoreInterface

protected DeletedFieldsRepositoryInterface deletedFieldsRepository()

Gets the deleted fields repository.

Inject this dependency in the constructor once this class can be instantiated as a regular entity handler: https://www.drupal.org/node/2332857.

Return Value

DeletedFieldsRepositoryInterface

The deleted fields repository.

protected KeyValueStoreInterface updateBackupRepository()

Gets the key/value collection for tracking the entity update backups.

Inject this dependency in the constructor once this class can be instantiated as a regular entity handler. @see https://www.drupal.org/node/2332857

Return Value

KeyValueStoreInterface

A key/value collection.

protected DefaultTableMapping getTableMapping(EntityTypeInterface $entity_type, array $storage_definitions = NULL)

Refreshes the table mapping with updated definitions.

Parameters

EntityTypeInterface $entity_type

An entity type definition.

array $storage_definitions

(optional) An array of field storage definitions. Defaults to the last installed field storage definition.

Return Value

DefaultTableMapping

A table mapping object.

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 hasSharedTableStructureChange(EntityTypeInterface $entity_type, EntityTypeInterface $original)

Detects whether there is a change in the shared table structure.

Parameters

EntityTypeInterface $entity_type

The new entity type.

EntityTypeInterface $original

The origin entity type.

Return Value

bool

Returns TRUE if either the revisionable or translatable flag changes or a table has been renamed.

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

Detects whether any table name got renamed in an entity type update.

Parameters

EntityTypeInterface $entity_type

The new entity type.

EntityTypeInterface $original

The origin entity type.

Return Value

bool

Returns TRUE if there have been changes.

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 array getSchemaFromStorageDefinition(FieldStorageDefinitionInterface $storage_definition)

Gets the schema data for the given field storage definition.

Parameters

FieldStorageDefinitionInterface $storage_definition

The field storage definition. The field that must not have custom storage, i.e. the storage must take care of storing the field.

Return Value

array

The schema data.

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.

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.

onEntityTypeCreate(EntityTypeInterface $entity_type)

Reacts to the creation of the entity type.

Parameters

EntityTypeInterface $entity_type

The entity type being created.

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.

onEntityTypeDelete(EntityTypeInterface $entity_type)

Reacts to the deletion of the entity type.

Parameters

EntityTypeInterface $entity_type

The entity type being deleted.

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.

static string getTemporaryTableMappingPrefix(EntityTypeInterface $entity_type, array $field_storage_definitions, string $first_prefix_part = 'tmp_')

internal  
 

Gets a string to be used as a prefix for a temporary table mapping object.

Parameters

EntityTypeInterface $entity_type

An entity type definition.

array $field_storage_definitions

An array of field storage definitions.

string $first_prefix_part

(optional) The first part of the prefix. Defaults to 'tmp_'.

Return Value

string

A temporary table mapping prefix.

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.

finalizePurge(FieldStorageDefinitionInterface $storage_definition)

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

Parameters

FieldStorageDefinitionInterface $storage_definition

The field being purged.

protected SelectInterface getSelectQueryForFieldStorageDeletion(string $table_name, array $shared_table_field_columns, array $dedicated_table_field_columns, string $base_table = NULL)

Returns a SELECT query suitable for inserting data into a dedicated table.

Parameters

string $table_name

The entity table name to select from.

array $shared_table_field_columns

An array of field column names for a shared table schema.

array $dedicated_table_field_columns

An array of field column names for a dedicated table schema.

string $base_table

(optional) The name of the base entity table. Defaults to NULL.

Return Value

SelectInterface

A database select query.

protected bool checkEntityType(EntityTypeInterface $entity_type)

Checks that we are dealing with the correct entity type.

Parameters

EntityTypeInterface $entity_type

The entity type to be checked.

Return Value

bool

TRUE if the entity type matches the current one.

Exceptions

EntityStorageException

protected array getEntitySchema(ContentEntityTypeInterface $entity_type, bool $reset = FALSE)

Gets the entity schema for the specified entity type.

Entity types may override this method in order to optimize the generated schema of the entity tables. However, only cross-field optimizations should be added here; e.g., an index spanning multiple fields. Optimizations that apply to a single field have to be added via SqlContentEntityStorageSchema::getSharedTableFieldSchema() instead.

Parameters

ContentEntityTypeInterface $entity_type

The entity type definition.

bool $reset

(optional) If set to TRUE static cache will be ignored and a new schema array generation will be performed. Defaults to FALSE.

Return Value

array

A Schema API array describing the entity schema, excluding dedicated field tables.

protected array getEntitySchemaTables(TableMappingInterface $table_mapping)

Gets a list of entity type tables.

Parameters

TableMappingInterface $table_mapping

A table mapping object.

Return Value

array

A list of entity type tables, keyed by table key.

protected array getEntitySchemaData(ContentEntityTypeInterface $entity_type, array $schema)

Gets entity schema definitions for index and key definitions.

Parameters

ContentEntityTypeInterface $entity_type

The entity type definition.

array $schema

The entity schema array.

Return Value

array

A stripped down version of the $schema Schema API array containing, for each table, only the key and index definitions not derived from field storage definitions.

protected array getFieldIndexes(string $field_name, array $field_schema, array $column_mapping)

Gets an index schema array for a given field.

Parameters

string $field_name

The name of the field.

array $field_schema

The schema of the field.

array $column_mapping

A mapping of field column names to database column names.

Return Value

array

The schema definition for the indexes.

protected array getFieldUniqueKeys(string $field_name, array $field_schema, array $column_mapping)

Gets a unique key schema array for a given field.

Parameters

string $field_name

The name of the field.

array $field_schema

The schema of the field.

array $column_mapping

A mapping of field column names to database column names.

Return Value

array

The schema definition for the unique keys.

protected array getFieldSchemaData(string $field_name, array $field_schema, array $column_mapping, string $schema_key)

Gets field schema data for the given key.

Parameters

string $field_name

The name of the field.

array $field_schema

The schema of the field.

array $column_mapping

A mapping of field column names to database column names.

string $schema_key

The type of schema data. Either 'indexes' or 'unique keys'.

Return Value

array

The schema definition for the specified key.

protected string getFieldSchemaIdentifierName(string $entity_type_id, string $field_name, string|null $key = NULL)

Generates a safe schema identifier (name of an index, column name etc.).

Parameters

string $entity_type_id

The ID of the entity type.

string $field_name

The name of the field.

string|null $key

(optional) A further key to append to the name.

Return Value

string

The field identifier name.

protected array getFieldForeignKeys(string $field_name, array $field_schema, array $column_mapping)

Gets field foreign keys.

Parameters

string $field_name

The name of the field.

array $field_schema

The schema of the field.

array $column_mapping

A mapping of field column names to database column names.

Return Value

array

The schema definition for the foreign keys.

protected array loadEntitySchemaData(EntityTypeInterface $entity_type)

Loads stored schema data for the given entity type definition.

Parameters

EntityTypeInterface $entity_type

The entity type definition.

Return Value

array

The entity schema data array.

protected saveEntitySchemaData(EntityTypeInterface $entity_type, array $schema)

Stores schema data for the given entity type definition.

Parameters

EntityTypeInterface $entity_type

The entity type definition.

array $schema

The entity schema data array.

protected deleteEntitySchemaData(EntityTypeInterface $entity_type)

Deletes schema data for the given entity type definition.

Parameters

EntityTypeInterface $entity_type

The entity type definition.

protected array loadFieldSchemaData(FieldStorageDefinitionInterface $storage_definition)

Loads stored schema data for the given field storage definition.

Parameters

FieldStorageDefinitionInterface $storage_definition

The field storage definition.

Return Value

array

The field schema data array.

protected saveFieldSchemaData(FieldStorageDefinitionInterface $storage_definition, array $schema)

Stores schema data for the given field storage definition.

Parameters

FieldStorageDefinitionInterface $storage_definition

The field storage definition.

array $schema

The field schema data array.

protected deleteFieldSchemaData(FieldStorageDefinitionInterface $storage_definition)

Deletes schema data for the given field storage definition.

Parameters

FieldStorageDefinitionInterface $storage_definition

The field storage definition.

protected array initializeBaseTable(ContentEntityTypeInterface $entity_type)

Initializes common information for a base table.

Parameters

ContentEntityTypeInterface $entity_type

The entity type.

Return Value

array

A partial schema array for the base table.

protected array initializeRevisionTable(ContentEntityTypeInterface $entity_type)

Initializes common information for a revision table.

Parameters

ContentEntityTypeInterface $entity_type

The entity type.

Return Value

array

A partial schema array for the revision table.

protected array initializeDataTable(ContentEntityTypeInterface $entity_type)

Initializes common information for a data table.

Parameters

ContentEntityTypeInterface $entity_type

The entity type.

Return Value

array

A partial schema array for the data table.

protected array initializeRevisionDataTable(ContentEntityTypeInterface $entity_type)

Initializes common information for a revision data table.

Parameters

ContentEntityTypeInterface $entity_type

The entity type.

Return Value

array

A partial schema array for the revision data table.

protected addTableDefaults($schema)

Adds defaults to a table schema definition.

Parameters

$schema

The schema definition array for a single table, passed by reference.

protected array processDataTable(ContentEntityTypeInterface $entity_type, array $schema)

Processes the gathered schema for a base table.

Parameters

ContentEntityTypeInterface $entity_type

The entity type.

array $schema

The table schema, passed by reference.

Return Value

array

A partial schema array for the base table.

protected array processRevisionDataTable(ContentEntityTypeInterface $entity_type, array $schema)

Processes the gathered schema for a base table.

Parameters

ContentEntityTypeInterface $entity_type

The entity type.

array $schema

The table schema, passed by reference.

Return Value

array

A partial schema array for the base table.

protected processIdentifierSchema(array $schema, string $key)

Processes the specified entity key.

Parameters

array $schema

The table schema, passed by reference.

string $key

The entity key name.

protected processFieldStorageSchema(array $field_storage_schema)

Processes the schema for a field storage definition.

Parameters

array $field_storage_schema

An array that contains the schema data for a field storage definition.

protected performFieldSchemaOperation(string $operation, FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original = NULL)

Performs the specified operation on a field.

This figures out whether the field is stored in a dedicated or shared table and forwards the call to the proper handler.

Parameters

string $operation

The name of the operation to be performed.

FieldStorageDefinitionInterface $storage_definition

The field storage definition.

FieldStorageDefinitionInterface $original

(optional) The original field storage definition. This is relevant (and required) only for updates. Defaults to NULL.

protected createDedicatedTableSchema(FieldStorageDefinitionInterface $storage_definition, bool $only_save = FALSE)

Creates the schema for a field stored in a dedicated table.

Parameters

FieldStorageDefinitionInterface $storage_definition

The storage definition of the field being created.

bool $only_save

(optional) Whether to skip modification of database tables and only save the schema data for future comparison. For internal use only. This is used by postUpdateEntityTypeSchema() after it has already fully created the dedicated tables.

protected createSharedTableSchema(FieldStorageDefinitionInterface $storage_definition, bool $only_save = FALSE)

Creates the schema for a field stored in a shared table.

Parameters

FieldStorageDefinitionInterface $storage_definition

The storage definition of the field being created.

bool $only_save

(optional) Whether to skip modification of database tables and only save the schema data for future comparison. For internal use only. This is used by onEntityTypeCreate() after it has already fully created the shared tables.

protected deleteDedicatedTableSchema(FieldStorageDefinitionInterface $storage_definition)

Deletes the schema for a field stored in a dedicated table.

Parameters

FieldStorageDefinitionInterface $storage_definition

The storage definition of the field being deleted.

protected deleteSharedTableSchema(FieldStorageDefinitionInterface $storage_definition)

Deletes the schema for a field stored in a shared table.

Parameters

FieldStorageDefinitionInterface $storage_definition

The storage definition of the field being deleted.

protected updateDedicatedTableSchema(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original)

Updates the schema for a field stored in a shared table.

Parameters

FieldStorageDefinitionInterface $storage_definition

The storage definition of the field being updated.

FieldStorageDefinitionInterface $original

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

Exceptions

FieldStorageDefinitionUpdateForbiddenException
Exception

protected updateSharedTableSchema(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original)

Updates the schema for a field stored in a shared table.

Parameters

FieldStorageDefinitionInterface $storage_definition

The storage definition of the field being updated.

FieldStorageDefinitionInterface $original

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

Exceptions

FieldStorageDefinitionUpdateForbiddenException
Exception

protected createEntitySchemaIndexes(array $entity_schema, FieldStorageDefinitionInterface $storage_definition = NULL)

Creates the specified entity schema indexes and keys.

Parameters

array $entity_schema

The entity schema definition.

FieldStorageDefinitionInterface $storage_definition

(optional) If a field storage definition is specified, only indexes and keys involving its columns will be processed. Otherwise all defined entity indexes and keys will be processed.

protected deleteEntitySchemaIndexes(array $entity_schema_data, FieldStorageDefinitionInterface $storage_definition = NULL)

Deletes the specified entity schema indexes and keys.

Parameters

array $entity_schema_data

The entity schema data definition.

FieldStorageDefinitionInterface $storage_definition

(optional) If a field storage definition is specified, only indexes and keys involving its columns will be processed. Otherwise all defined entity indexes and keys will be processed.

protected bool hasNullFieldPropertyData(string $table_name, string $column_name)

Checks whether a field property has NULL values.

Parameters

string $table_name

The name of the table to inspect.

string $column_name

The name of the column holding the field property data.

Return Value

bool

TRUE if NULL data is found, FALSE otherwise.

protected array getSharedTableFieldSchema(FieldStorageDefinitionInterface $storage_definition, string $table_name, array $column_mapping)

Gets the schema for a single field definition.

Entity types may override this method in order to optimize the generated schema for given field. While all optimizations that apply to a single field have to be added here, all cross-field optimizations should be via SqlContentEntityStorageSchema::getEntitySchema() instead; e.g., an index spanning multiple fields.

Parameters

FieldStorageDefinitionInterface $storage_definition

The storage definition of the field whose schema has to be returned.

string $table_name

The name of the table columns will be added to.

array $column_mapping

A mapping of field column names to database column names.

Return Value

array

The schema definition for the table with the following keys:

  • fields: The schema definition for the each field columns.
  • indexes: The schema definition for the indexes.
  • unique keys: The schema definition for the unique keys.
  • foreign keys: The schema definition for the foreign keys.

Exceptions

FieldException

protected addSharedTableFieldIndex(FieldStorageDefinitionInterface $storage_definition, array $schema, bool $not_null = FALSE, int $size = NULL)

Adds an index for the specified field to the given schema definition.

Parameters

FieldStorageDefinitionInterface $storage_definition

The storage definition of the field for which an index should be added.

array $schema

A reference to the schema array to be updated.

bool $not_null

(optional) Whether to also add a 'not null' constraint to the column being indexed. Doing so improves index performance. Defaults to FALSE, in case the field needs to support NULL values.

int $size

(optional) The index size. Defaults to no limit.

protected addSharedTableFieldUniqueKey(FieldStorageDefinitionInterface $storage_definition, array $schema)

Adds a unique key for the specified field to the given schema definition.

Also adds a 'not null' constraint, because many databases do not reliably support unique keys on null columns.

Parameters

FieldStorageDefinitionInterface $storage_definition

The storage definition of the field to which to add a unique key.

array $schema

A reference to the schema array to be updated.

protected addSharedTableFieldForeignKey(FieldStorageDefinitionInterface $storage_definition, array $schema, string $foreign_table, string $foreign_column)

Adds a foreign key for the specified field to the given schema definition.

Parameters

FieldStorageDefinitionInterface $storage_definition

The storage definition of the field to which to add a foreign key.

array $schema

A reference to the schema array to be updated.

string $foreign_table

The foreign table.

string $foreign_column

The foreign column.

protected array getDedicatedTableSchema(FieldStorageDefinitionInterface $storage_definition, ContentEntityTypeInterface $entity_type = NULL)

Gets the SQL schema for a dedicated table.

Parameters

FieldStorageDefinitionInterface $storage_definition

The field storage definition.

ContentEntityTypeInterface $entity_type

(optional) The entity type definition. Defaults to the one provided by the entity storage.

Return Value

array

The schema definition for the table with the following keys:

  • fields: The schema definition for the each field columns.
  • indexes: The schema definition for the indexes.
  • unique keys: The schema definition for the unique keys.
  • foreign keys: The schema definition for the foreign keys.

Exceptions

FieldException

See also

hook_schema()

protected string getEntityIndexName(ContentEntityTypeInterface $entity_type, string $index)

Gets the name to be used for the given entity index.

Parameters

ContentEntityTypeInterface $entity_type

The entity type.

string $index

The index column name.

Return Value

string

The index name.

protected string getFieldIndexName(FieldStorageDefinitionInterface $storage_definition, string $index)

Generates an index name for a field data table.

Parameters

FieldStorageDefinitionInterface $storage_definition

The field storage definition.

string $index

The name of the index.

Return Value

string

A string containing a generated index name for a field data table that is unique among all other fields.

protected bool isTableEmpty(string $table_name)

Checks whether a database table is non-existent or empty.

Empty tables can be dropped and recreated without data loss.

Parameters

string $table_name

The database table to check.

Return Value

bool

TRUE if the table is empty, FALSE otherwise.

protected bool hasColumnChanges(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original)

Compares schemas to check for changes in the column definitions.

Parameters

FieldStorageDefinitionInterface $storage_definition

Current field storage definition.

FieldStorageDefinitionInterface $original

The original field storage definition.

Return Value

bool

Returns TRUE if there are schema changes in the column definitions.

protected string[] getColumnSchemaRelevantKeys()

Returns a list of column schema keys affecting data storage.

When comparing schema definitions, only changes in certain properties actually affect how data is stored and thus, if applied, may imply data manipulation.

Return Value

string[]

An array of key names.

protected addIndex(string $table, string $name, array $specifier, array $schema)

Creates an index, dropping it if already existing.

Parameters

string $table

The table name.

string $name

The index name.

array $specifier

The fields to index.

array $schema

The table specification.

See also

Schema::addIndex

protected addUniqueKey(string $table, string $name, array $specifier)

Creates a unique key, dropping it if already existing.

Parameters

string $table

The table name.

string $name

The index name.

array $specifier

The unique fields.

See also

Schema::addUniqueKey

static mixed castValue(array $info, mixed $value)

internal  
 

Typecasts values to proper datatypes.

MySQL PDO silently casts, e.g. FALSE and '' to 0, when inserting the value into an integer column, but PostgreSQL PDO does not. Use the schema information to correctly typecast the value.

Parameters

array $info

An array describing the schema field info. See hook_schema() and https://www.drupal.org/node/146843 for details.

mixed $value

The value to be converted.

Return Value

mixed

The converted value.

See also

hook_schema()
https://www.drupal.org/node/146843