3 namespace Drupal\Core\Entity\Sql;
5 use Drupal\Core\Field\FieldStorageDefinitionInterface;
8 * Provides a common interface for mapping field columns to SQL tables.
10 * Warning: using methods provided here should be done only when writing code
11 * that is explicitly targeting a SQL-based entity storage. Typically this API
12 * is used by SQL storage classes, or other SQL-specific code like the Views
13 * integration code for the Entity SQL storage. Another example of legal usage
14 * of this API is when needing to write a query that \Drupal::entityQuery() does
15 * not support. Always retrieve entity identifiers and use them to load entities
16 * instead of accessing data stored in the database directly. Any other usage
17 * circumvents the entity system and is strongly discouraged, at least when
18 * writing contributed code.
20 interface TableMappingInterface {
23 * A property that represents delta used in entity query conditions.
25 const DELTA = '%delta';
28 * Gets a list of table names for this mapping.
31 * An array of table names.
33 public function getTableNames();
36 * Gets a list of all database columns for a given table.
38 * @param string $table_name
39 * The name of the table to return the columns for.
42 * An array of database column names for this table. Both field columns and
43 * extra columns are returned.
45 public function getAllColumns($table_name);
48 * Gets a list of names for entity fields stored in the specified table.
50 * The return list is contains the entity field names, not database field
51 * (i.e. column) names. To get the mapping of specific entity field to
52 * database columns use ::getColumnNames().
54 * @param string $table_name
55 * The name of the table to return the field names for.
58 * An array of field names for the given table.
60 public function getFieldNames($table_name);
63 * Gets a mapping of field columns to database columns for a given field.
65 * @param string $field_name
66 * The name of the entity field to return the column mapping for.
69 * The keys of this array are the keys of the array returned by
70 * FieldStorageDefinitionInterface::getColumns() while the respective values
71 * are the names of the database columns for this table mapping.
73 public function getColumnNames($field_name);
76 * Gets a list of extra database columns, which store denormalized data.
78 * These database columns do not belong to any entity fields. Any normalized
79 * data that is stored should be associated with an entity field.
81 * @param string $table_name
82 * The name of the table to return the columns for.
85 * An array of column names for the given table.
87 public function getExtraColumns($table_name);
90 * Gets the list of columns that can not be used as field type columns.
94 public function getReservedColumns();
97 * Generates a column name for a field property.
99 * @param \Drupal\Core\Field\FieldStorageDefinitionInterface $storage_definition
100 * The field storage definition.
101 * @param string $property_name
102 * The name of the property.
105 * A string containing a generated column name for a field data table that is
106 * unique among all other fields.
108 public function getFieldColumnName(FieldStorageDefinitionInterface $storage_definition, $property_name);
111 * Gets the table name for a given column.
113 * @param string $field_name
114 * The name of the entity field to return the column mapping for.
117 * Table name for the given field.
119 * @throws \Drupal\Core\Entity\Sql\SqlContentEntityStorageException
121 public function getFieldTableName($field_name);