function Tables::ensureFieldTable
Same name in other branches
- 8.9.x core/lib/Drupal/Core/Entity/Query/Sql/Tables.php \Drupal\Core\Entity\Query\Sql\Tables::ensureFieldTable()
- 10 core/lib/Drupal/Core/Entity/Query/Sql/Tables.php \Drupal\Core\Entity\Query\Sql\Tables::ensureFieldTable()
- 11.x core/lib/Drupal/Core/Entity/Query/Sql/Tables.php \Drupal\Core\Entity\Query\Sql\Tables::ensureFieldTable()
Ensure the field table is joined if necessary.
Parameters
string $index_prefix: The table array index prefix. For a base table this will be empty, for a target entity reference like 'field_tags.entity:taxonomy_term.name' this will be 'entity:taxonomy_term.target_id.'.
\Drupal\Core\Field\FieldStorageDefinitionInterface &$field: The field storage definition for the field being joined.
string $type: The join type.
string $langcode: The langcode we use on the join.
string $base_table: The table to join to. It can be either the table name, its alias or the 'base_table' placeholder.
string $entity_id_field: The name of the ID field/property for the current entity. For instance: tid, nid, etc.
string $field_id_field: The column representing the id for the field. For example, 'revision_id' or 'entity_id'.
string $delta: A delta which should be used as additional condition.
Return value
string The alias of the joined table.
1 call to Tables::ensureFieldTable()
- Tables::addField in core/
lib/ Drupal/ Core/ Entity/ Query/ Sql/ Tables.php - Adds a field to a database query.
File
-
core/
lib/ Drupal/ Core/ Entity/ Query/ Sql/ Tables.php, line 400
Class
- Tables
- Adds tables and fields to the SQL entity query.
Namespace
Drupal\Core\Entity\Query\SqlCode
protected function ensureFieldTable($index_prefix, &$field, $type, $langcode, $base_table, $entity_id_field, $field_id_field, $delta) {
$field_name = $field->getName();
if (!isset($this->fieldTables[$index_prefix . $field_name])) {
$entity_type_id = $this->sqlQuery
->getMetaData('entity_type');
/** @var \Drupal\Core\Entity\Sql\DefaultTableMapping $table_mapping */
$table_mapping = $this->entityTypeManager
->getStorage($entity_type_id)
->getTableMapping();
$table = !$this->sqlQuery
->getMetaData('all_revisions') ? $table_mapping->getDedicatedDataTableName($field) : $table_mapping->getDedicatedRevisionTableName($field);
if ($field->getCardinality() != 1) {
$this->sqlQuery
->addMetaData('simple_query', FALSE);
}
$this->fieldTables[$index_prefix . $field_name] = $this->addJoin($type, $table, "[%alias].[{$field_id_field}] = [{$base_table}].[{$entity_id_field}]", $langcode, $delta);
}
return $this->fieldTables[$index_prefix . $field_name];
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.