protected function EntityQueryAlter::ensureDataTable in Group 2.0.x
Same name and namespace in other branches
- 8 src/QueryAccess/EntityQueryAlter.php \Drupal\group\QueryAccess\EntityQueryAlter::ensureDataTable()
Ensures the query is joined against the data table.
Parameters
string $base_table: The alias of the base table.
\Drupal\Core\Database\Query\SelectInterface $query: The select query.
\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type.
Return value
string The data table alias.
1 call to EntityQueryAlter::ensureDataTable()
- EntityQueryAlter::doAlter in src/
QueryAccess/ EntityQueryAlter.php - Actually alters the select query for the given entity type.
File
- src/
QueryAccess/ EntityQueryAlter.php, line 506
Class
- EntityQueryAlter
- Defines a class for altering entity queries.
Namespace
Drupal\group\QueryAccessCode
protected function ensureDataTable($base_table, SelectInterface $query, EntityTypeInterface $entity_type) {
if ($this->dataTableAlias === FALSE) {
if (!($data_table = $entity_type
->getDataTable())) {
$data_table = $base_table;
$data_table_found = TRUE;
}
else {
$data_table_found = FALSE;
foreach ($query
->getTables() as $alias => $table) {
if (!$data_table_found && ($table['join type'] === 'INNER' || $alias === $base_table) && $table['table'] === $data_table) {
$data_table = $alias;
$data_table_found = TRUE;
break;
}
}
}
// If the data table wasn't added to the query yet, add it here.
if (!$data_table_found) {
$id_key = $entity_type
->getKey('id');
$this->dataTableAlias = $query
->join($data_table, $data_table, "{$base_table}.{$id_key}={$data_table}.{$id_key}");
}
else {
$this->dataTableAlias = $data_table;
}
}
return $this->dataTableAlias;
}