You are here

function Sql::get_entity_tables in Views (for Drupal 7) 8.3

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::get_entity_tables()
Sql::load_entities in 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 lib/Drupal/views/Plugin/views/query/Sql.php
Generate a query and a countquery from all of the information supplied to the object.

File

lib/Drupal/views/Plugin/views/query/Sql.php, line 1540
Definition of Drupal\views\Plugin\views\query\Sql.

Class

Sql
@todo.

Namespace

Drupal\views\Plugin\views\query

Code

function get_entity_tables() {

  // Start with the base table.
  $entity_tables = array();
  $base_table_data = views_fetch_data($this->base_table);
  if (isset($base_table_data['table']['entity type'])) {
    $entity_tables[$this->base_table] = array(
      'base' => $this->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_fetch_data($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;
}