function DefaultTableMapping::getFieldTableName

Same name in other branches
  1. 9 core/lib/Drupal/Core/Entity/Sql/DefaultTableMapping.php \Drupal\Core\Entity\Sql\DefaultTableMapping::getFieldTableName()
  2. 10 core/lib/Drupal/Core/Entity/Sql/DefaultTableMapping.php \Drupal\Core\Entity\Sql\DefaultTableMapping::getFieldTableName()
  3. 11.x core/lib/Drupal/Core/Entity/Sql/DefaultTableMapping.php \Drupal\Core\Entity\Sql\DefaultTableMapping::getFieldTableName()

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\Sql

Code

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.