public function Sql::getEntityTables

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".
  • 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.

2 calls to Sql::getEntityTables()
Sql::loadEntities in drupal/core/modules/views/lib/Drupal/views/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 drupal/core/modules/views/lib/Drupal/views/Plugin/views/query/Sql.php
Generate a query and a countquery from all of the information supplied to the object.

File

drupal/core/modules/views/lib/Drupal/views/Plugin/views/query/Sql.php, line 1472
Definition of Drupal\views\Plugin\views\query\Sql.

Class

Sql
@todo.

Namespace

Drupal\views\Plugin\views\query

Code

public function getEntityTables() {

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

  // Include all relationships.
  foreach ($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->alias] = array(
        'base' => $relationship->definition['base'],
        'relationship_id' => $relationship_id,
        'entity_type' => $table_data['table']['entity type'],
        'revision' => FALSE,
      );
    }
  }

  // Determine which of the tables are revision tables.
  foreach ($entity_tables as $table_alias => $table) {
    $info = entity_get_info($table['entity_type']);
    if (isset($info['revision table']) && $info['revision table'] == $table['base']) {
      $entity_tables[$table_alias]['revision'] = TRUE;
    }
  }
  return $entity_tables;
}