function QueryPluginBase::getEntityTableInfo
Same name in other branches
- 9 core/modules/views/src/Plugin/views/query/QueryPluginBase.php \Drupal\views\Plugin\views\query\QueryPluginBase::getEntityTableInfo()
- 8.9.x core/modules/views/src/Plugin/views/query/QueryPluginBase.php \Drupal\views\Plugin\views\query\QueryPluginBase::getEntityTableInfo()
- 10 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.
- Sql::query in core/
modules/ views/ src/ Plugin/ views/ query/ Sql.php - Generates a query and count query from all of the information supplied.
File
-
core/
modules/ views/ src/ Plugin/ views/ query/ QueryPluginBase.php, line 278
Class
- QueryPluginBase
- Base plugin class for Views queries.
Namespace
Drupal\views\Plugin\views\queryCode
public function getEntityTableInfo() {
// Start with the base table.
$entity_tables = [];
$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']] = [
'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'])) {
// If this is not one of the entity base tables, skip it.
$entity_type = \Drupal::entityTypeManager()->getDefinition($table_data['table']['entity type']);
$entity_base_tables = [
$entity_type->getBaseTable(),
$entity_type->getDataTable(),
$entity_type->getRevisionTable(),
$entity_type->getRevisionDataTable(),
];
if (!in_array($relationship->definition['base'], $entity_base_tables)) {
continue;
}
$entity_tables[$relationship_id . '__' . $relationship->tableAlias] = [
'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::entityTypeManager()->getDefinition($table['entity_type']);
if ($entity_type->getRevisionTable() == $table['base']) {
$entity_tables[$table_alias]['revision'] = TRUE;
}
}
return $entity_tables;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.