class DefaultTableMapping implements TableMappingInterface (View source)

Defines a default table mapping class.

Properties

protected ContentEntityTypeInterface $entityType

The entity type definition.

protected FieldStorageDefinitionInterface[] $fieldStorageDefinitions

The field storage definitions of this mapping.

protected string $prefix

The prefix to be used by all the tables of this mapping.

protected string $baseTable

The base table of the entity.

protected string $revisionTable

The table that stores revisions, if the entity supports revisions.

protected string $dataTable

The table that stores field data, if the entity has multilingual support.

protected string $revisionDataTable

The table that stores revision field data if the entity supports revisions and has multilingual support.

protected array[] $fieldNames

A list of field names per table.

protected array[] $extraColumns

A list of database columns which store denormalized data per table.

protected array[] $columnMapping

A mapping of column names per field name.

protected array[] $allColumns

A list of all database columns per table.

Methods

__construct(ContentEntityTypeInterface $entity_type, array $storage_definitions, string $prefix = '')

Constructs a DefaultTableMapping.

create(ContentEntityTypeInterface $entity_type, array $storage_definitions, string $prefix = '')

Initializes the table mapping.

string
getBaseTable()

Gets the base table name.

string|null
getRevisionTable()

Gets the revision table name.

string|null
getDataTable()

Gets the data table name.

string|null
getRevisionDataTable()

Gets the revision data table name.

string[]
getTableNames()

Gets a list of table names for this mapping.

string[]
getAllColumns(string $table_name)

Gets a list of all database columns for a given table.

string[]
getFieldNames(string $table_name)

Gets a list of names for entity fields stored in the specified table.

string
getFieldTableName(string $field_name)

Gets the table name for a given column.

string[]
getAllFieldTableNames(string $field_name)

Gets all the table names in which an entity field is stored.

string[]
getColumnNames(string $field_name)

Gets a mapping of field columns to database columns for a given field.

string
getFieldColumnName(FieldStorageDefinitionInterface $storage_definition, string $property_name)

Generates a column name for a field property.

$this
setFieldNames(string $table_name, array $field_names)

Adds field columns for a table to the table mapping.

string[]
getExtraColumns(string $table_name)

Gets a list of extra database columns, which store denormalized data.

$this
setExtraColumns(string $table_name, array $column_names)

Adds extra columns for a table to the table mapping.

bool
allowsSharedTableStorage(FieldStorageDefinitionInterface $storage_definition)

Checks whether the given field can be stored in a shared table.

bool
requiresDedicatedTableStorage(FieldStorageDefinitionInterface $storage_definition)

Checks whether the given field has to be stored in a dedicated table.

string[]
getDedicatedTableNames()

Gets a list of dedicated table names for this mapping.

array
getReservedColumns()

Gets the list of columns that can not be used as field type columns.

string
getDedicatedDataTableName(FieldStorageDefinitionInterface $storage_definition, bool $is_deleted = FALSE)

Generates a table name for a field data table.

string
getDedicatedRevisionTableName(FieldStorageDefinitionInterface $storage_definition, bool $is_deleted = FALSE)

Generates a table name for a field revision archive table.

string
generateFieldTableName(FieldStorageDefinitionInterface $storage_definition, bool $revision)

Generates a safe and unambiguous field table name.

Details

__construct(ContentEntityTypeInterface $entity_type, array $storage_definitions, string $prefix = '')

Constructs a DefaultTableMapping.

Parameters

ContentEntityTypeInterface $entity_type

The entity type definition.

array $storage_definitions

A list of field storage definitions that should be available for the field columns of this table mapping.

string $prefix

(optional) A prefix to be used by all the tables of this mapping. Defaults to an empty string.

static DefaultTableMapping create(ContentEntityTypeInterface $entity_type, array $storage_definitions, string $prefix = '')

internal  
 

Initializes the table mapping.

Parameters

ContentEntityTypeInterface $entity_type

The entity type definition.

array $storage_definitions

A list of field storage definitions that should be available for the field columns of this table mapping.

string $prefix

(optional) A prefix to be used by all the tables of this mapping. Defaults to an empty string.

Return Value

DefaultTableMapping

string getBaseTable()

internal  
 

Gets the base table name.

Return Value

string

The base table name.

string|null getRevisionTable()

internal  
 

Gets the revision table name.

Return Value

string|null

The revision table name.

string|null getDataTable()

internal  
 

Gets the data table name.

Return Value

string|null

The data table name.

string|null getRevisionDataTable()

internal  
 

Gets the revision data table name.

Return Value

string|null

The revision data table name.

string[] getTableNames()

Gets a list of table names for this mapping.

Return Value

string[]

An array of table names.

string[] getAllColumns(string $table_name)

Gets a list of all database columns for a given table.

Parameters

string $table_name

The name of the table to return the columns for.

Return Value

string[]

An array of database column names for this table. Both field columns and extra columns are returned.

string[] getFieldNames(string $table_name)

Gets a list of names for entity fields stored in the specified table.

The return list is contains the entity field names, not database field (i.e. column) names. To get the mapping of specific entity field to database columns use ::getColumnNames().

Parameters

string $table_name

The name of the table to return the field names for.

Return Value

string[]

An array of field names for the given table.

string getFieldTableName(string $field_name)

Gets the table name for a given column.

Parameters

string $field_name

The name of the entity field to return the column mapping for.

Return Value

string

Table name for the given field.

Exceptions

SqlContentEntityStorageException

string[] getAllFieldTableNames(string $field_name)

Gets all the table names in which an entity field is stored.

The returned table names are ordered by the amount of data stored in each table. For example, a revisionable and translatable entity type which uses core's default table mapping strategy would return the table names for the entity ID field in the following order:

  • base table
  • data table
  • revision table
  • revision data table

Parameters

string $field_name

The name of the entity field to return the tables names for.

Return Value

string[]

An array of table names in which the given field is stored.

Exceptions

SqlContentEntityStorageException

string[] getColumnNames(string $field_name)

Gets a mapping of field columns to database columns for a given field.

Parameters

string $field_name

The name of the entity field to return the column mapping for.

Return Value

string[]

The keys of this array are the keys of the array returned by FieldStorageDefinitionInterface::getColumns() while the respective values are the names of the database columns for this table mapping.

string getFieldColumnName(FieldStorageDefinitionInterface $storage_definition, string $property_name)

Generates a column name for a field property.

Parameters

FieldStorageDefinitionInterface $storage_definition

The field storage definition.

string $property_name

The name of the property.

Return Value

string

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

$this setFieldNames(string $table_name, array $field_names)

internal  
 

Adds field columns for a table to the table mapping.

Make this method protected in drupal:9.0.0.

Parameters

string $table_name

The name of the table to add the field column for.

array $field_names

A list of field names to add the columns for.

Return Value

$this

See also

https://www.drupal.org/node/3067336

string[] getExtraColumns(string $table_name)

Gets a list of extra database columns, which store denormalized data.

These database columns do not belong to any entity fields. Any normalized data that is stored should be associated with an entity field.

Parameters

string $table_name

The name of the table to return the columns for.

Return Value

string[]

An array of column names for the given table.

$this setExtraColumns(string $table_name, array $column_names)

internal  
 

Adds extra columns for a table to the table mapping.

Make this method protected in drupal:9.0.0.

Parameters

string $table_name

The name of table to add the extra columns for.

array $column_names

The list of column names.

Return Value

$this

See also

https://www.drupal.org/node/3067336

bool allowsSharedTableStorage(FieldStorageDefinitionInterface $storage_definition)

Checks whether the given field can be stored in a shared table.

Parameters

FieldStorageDefinitionInterface $storage_definition

The field storage definition.

Return Value

bool

TRUE if the field can be stored in a shared table, FALSE otherwise.

bool requiresDedicatedTableStorage(FieldStorageDefinitionInterface $storage_definition)

Checks whether the given field has to be stored in a dedicated table.

Parameters

FieldStorageDefinitionInterface $storage_definition

The field storage definition.

Return Value

bool

TRUE if the field has to be stored in a dedicated table, FALSE otherwise.

string[] getDedicatedTableNames()

Gets a list of dedicated table names for this mapping.

Return Value

string[]

An array of table names.

array getReservedColumns()

Gets the list of columns that can not be used as field type columns.

Return Value

array

string getDedicatedDataTableName(FieldStorageDefinitionInterface $storage_definition, bool $is_deleted = FALSE)

Generates a table name for a field data table.

Parameters

FieldStorageDefinitionInterface $storage_definition

The field storage definition.

bool $is_deleted

(optional) Whether the table name holding the values of a deleted field should be returned.

Return Value

string

A string containing the generated name for the database table.

string getDedicatedRevisionTableName(FieldStorageDefinitionInterface $storage_definition, bool $is_deleted = FALSE)

Generates a table name for a field revision archive table.

Parameters

FieldStorageDefinitionInterface $storage_definition

The field storage definition.

bool $is_deleted

(optional) Whether the table name holding the values of a deleted field should be returned.

Return Value

string

A string containing the generated name for the database table.

protected string generateFieldTableName(FieldStorageDefinitionInterface $storage_definition, bool $revision)

Generates a safe and unambiguous field table name.

The method accounts for a maximum table name length of 64 characters, and takes care of disambiguation.

Parameters

FieldStorageDefinitionInterface $storage_definition

The field storage definition.

bool $revision

TRUE for revision table, FALSE otherwise.

Return Value

string

The final table name.