You are here

public function QueryPluginBase::getEntityTableInfo in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views/src/Plugin/views/query/QueryPluginBase.php \Drupal\views\Plugin\views\query\QueryPluginBase::getEntityTableInfo()

Returns an array of all tables from the query that map to an entity type.

Includes the base table and all relationships, if eligible.

Available keys for each table:

  • base: The actual base table (i.e. "user" for an author relationship).
  • relationship_id: The id of the relationship, or "none".
  • alias: The alias used for the relationship.
  • entity_type: The entity type matching the base table.
  • revision: A boolean that specifies whether the table is a base table or a revision table of the entity type.

Return value

array An array of table information, keyed by table alias.

3 calls to QueryPluginBase::getEntityTableInfo()
QueryPluginBase::calculateDependencies in core/modules/views/src/Plugin/views/query/QueryPluginBase.php
Calculates dependencies for the configured plugin.
Sql::loadEntities in core/modules/views/src/Plugin/views/query/Sql.php
Loads all entities contained in the passed-in $results. . If the entity belongs to the base table, then it gets stored in $result->_entity. Otherwise, it gets stored in $result->_relationship_entities[$relationship_id];
Sql::query in core/modules/views/src/Plugin/views/query/Sql.php
Generate a query and a countquery from all of the information supplied to the object.

File

core/modules/views/src/Plugin/views/query/QueryPluginBase.php, line 267
Contains \Drupal\views\Plugin\views\query\QueryPluginBase.

Class

QueryPluginBase
Base plugin class for Views queries.

Namespace

Drupal\views\Plugin\views\query

Code

public function getEntityTableInfo() {

  // Start with the base table.
  $entity_tables = array();
  $views_data = Views::viewsData();
  $base_table = $this->view->storage
    ->get('base_table');
  $base_table_data = $views_data
    ->get($base_table);
  if (isset($base_table_data['table']['entity type'])) {
    $entity_tables[$base_table_data['table']['entity type']] = array(
      'base' => $base_table,
      'alias' => $base_table,
      'relationship_id' => 'none',
      'entity_type' => $base_table_data['table']['entity type'],
      'revision' => $base_table_data['table']['entity revision'],
    );

    // Include the entity provider.
    if (!empty($base_table_data['table']['provider'])) {
      $entity_tables[$base_table_data['table']['entity type']]['provider'] = $base_table_data['table']['provider'];
    }
  }

  // Include all relationships.
  foreach ((array) $this->view->relationship as $relationship_id => $relationship) {
    $table_data = $views_data
      ->get($relationship->definition['base']);
    if (isset($table_data['table']['entity type'])) {
      $entity_tables[$relationship_id . '__' . $relationship->tableAlias] = array(
        'base' => $relationship->definition['base'],
        'relationship_id' => $relationship_id,
        'alias' => $relationship->alias,
        'entity_type' => $table_data['table']['entity type'],
        'revision' => $table_data['table']['entity revision'],
      );

      // Include the entity provider.
      if (!empty($table_data['table']['provider'])) {
        $entity_tables[$relationship_id . '__' . $relationship->tableAlias]['provider'] = $table_data['table']['provider'];
      }
    }
  }

  // Determine which of the tables are revision tables.
  foreach ($entity_tables as $table_alias => $table) {
    $entity_type = \Drupal::entityManager()
      ->getDefinition($table['entity_type']);
    if ($entity_type
      ->getRevisionTable() == $table['base']) {
      $entity_tables[$table_alias]['revision'] = TRUE;
    }
  }
  return $entity_tables;
}