public function DefaultTableMapping::getFieldTableName in Zircon Profile 8.0
Same name and namespace in other branches
- 8 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 142 - Contains \Drupal\Core\Entity\Sql\DefaultTableMapping.
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.
// @todo The table mapping itself should know about entity tables. See
// https://www.drupal.org/node/2274017.
/** @var \Drupal\Core\Entity\Sql\SqlContentEntityStorage $storage */
$storage = \Drupal::entityManager()
->getStorage($this->entityType
->id());
$table_names = array(
$storage
->getDataTable(),
$storage
->getBaseTable(),
$storage
->getRevisionTable(),
);
// Collect field columns.
$field_columns = array();
$storage_definition = $this->fieldStorageDefinitions[$field_name];
foreach (array_keys($storage_definition
->getColumns()) as $property_name) {
$field_columns[] = $this
->getFieldColumnName($storage_definition, $property_name);
}
foreach (array_filter($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;
}