You are here

class Tables in Dynamic Entity Reference 8.2

Adds tables and fields to the SQL entity query.

Hierarchy

Expanded class hierarchy of Tables

File

src/Query/Tables.php, line 13

Namespace

Drupal\dynamic_entity_reference\Query
View source
class Tables extends BaseTables {

  /**
   * {@inheritdoc}
   */
  protected function addNextBaseTable(EntityType $entity_type, $table, $sql_column, FieldStorageDefinitionInterface $field_storage = NULL) {

    // Parent method is overridden in order to choose the correct columns to
    // join on (string or int for the id and type for the entity type
    // specifier).
    $entity_type_id_key = $entity_type
      ->getKey('id');
    $entity_type_id = $entity_type
      ->id();
    $join_condition_type = '';
    if ($field_storage && $field_storage
      ->getType() === 'dynamic_entity_reference' && $entity_type_id_key !== FALSE) {

      // DER basefield SQL column are named entity_name__target_id and
      // entity_name__target_type where as config field columns are named
      // field_name_target_id and field_name_target_type.
      $sql_column_type = str_replace('target_id', 'target_type', $sql_column);
      if (DynamicEntityReferenceItem::entityHasIntegerId($entity_type_id)) {
        $sql_column .= '_int';
      }

      // Prepare to modify the join with an entity type specifier. This can
      // prevent obscure cases where entities of different types (e.g. node vs.
      // taxonomy_term) with the same id are returned.
      $join_condition_type = " AND [{$table}].[{$sql_column_type}] = '{$entity_type_id}'";
    }
    $join_condition = "[%alias].[{$entity_type_id_key}] = [{$table}].[{$sql_column}]" . $join_condition_type;
    return $this->sqlQuery
      ->leftJoin($entity_type
      ->getBaseTable(), NULL, $join_condition);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DeprecatedServicePropertyTrait::__get public function Allows to access deprecated/removed properties.
Tables::$caseSensitiveFields protected property List of case sensitive fields.
Tables::$deprecatedProperties protected property
Tables::$entityFieldManager protected property The entity field manager.
Tables::$entityTables protected property Entity table array.
Tables::$entityTypeManager protected property The entity type manager.
Tables::$fieldTables protected property Field table array, key is table name, value is alias.
Tables::$sqlQuery protected property
Tables::addField public function Adds a field to a database query. Overrides TablesInterface::addField 1
Tables::addJoin protected function Adds a join to a given table. 1
Tables::addNextBaseTable protected function Add the next entity base table. Overrides Tables::addNextBaseTable
Tables::ensureEntityTable protected function Joins the entity table, if necessary, and returns the alias for it.
Tables::ensureFieldTable protected function Join field table if necessary.
Tables::getTableMapping protected function Gets the schema for the given table.
Tables::isFieldCaseSensitive public function Determines whether the given field is case sensitive. Overrides TablesInterface::isFieldCaseSensitive
Tables::__construct public function 1