public function DefaultTableMapping::getFieldTableName in Drupal 8
Same name and namespace in other branches
- 9 core/lib/Drupal/Core/Entity/Sql/DefaultTableMapping.php \Drupal\Core\Entity\Sql\DefaultTableMapping::getFieldTableName()
- 10 core/lib/Drupal/Core/Entity/Sql/DefaultTableMapping.php \Drupal\Core\Entity\Sql\DefaultTableMapping::getFieldTableName()
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.
Throws
\Drupal\Core\Entity\Sql\SqlContentEntityStorageException
Overrides TableMappingInterface::getFieldTableName
File
- core/
lib/ Drupal/ Core/ Entity/ Sql/ DefaultTableMapping.php, line 356
Class
- DefaultTableMapping
- Defines a default table mapping class.
Namespace
Drupal\Core\Entity\SqlCode
public function getFieldTableName($field_name) {
$result = NULL;
if (isset($this->fieldStorageDefinitions[$field_name])) {
// Since a field may be stored in more than one table, we inspect tables
// in order of relevance: the data table if present is the main place
// where field data is stored, otherwise the base table is responsible for
// storing field data. Revision metadata is an exception as it's stored
// only in the revision table.
$storage_definition = $this->fieldStorageDefinitions[$field_name];
$table_names = array_filter([
$this->dataTable,
$this->baseTable,
$this->revisionTable,
$this
->getDedicatedDataTableName($storage_definition),
]);
// Collect field columns.
$field_columns = [];
foreach (array_keys($storage_definition
->getColumns()) as $property_name) {
$field_columns[] = $this
->getFieldColumnName($storage_definition, $property_name);
}
foreach ($table_names as $table_name) {
$columns = $this
->getAllColumns($table_name);
// We assume finding one field column belonging to the mapping is enough
// to identify the field table.
if (array_intersect($columns, $field_columns)) {
$result = $table_name;
break;
}
}
}
if (!isset($result)) {
throw new SqlContentEntityStorageException("Table information not available for the '{$field_name}' field.");
}
return $result;
}