You are here

protected function Tables::ensureFieldTable in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Entity/Query/Sql/Tables.php \Drupal\Core\Entity\Query\Sql\Tables::ensureFieldTable()

Join field table if necessary.

Parameters

$field_name: Name of the field.

Return value

string

Throws

\Drupal\Core\Entity\Query\QueryException

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 381

Class

Tables
Adds tables and fields to the SQL entity query.

Namespace

Drupal\Core\Entity\Query\Sql

Code

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