private function NodeTypeAccessService::extractBaseTableAlias in Nodetype access 8
Extract base table alias.
Parameters
\Drupal\Core\Database\Query\AlterableInterface $query:
Return value
string|null
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
\Drupal\Component\Plugin\Exception\PluginNotFoundException
\Exception
1 call to NodeTypeAccessService::extractBaseTableAlias()
File
- src/
NodeTypeAccessService.php, line 118
Class
Namespace
Drupal\nodetype_accessCode
private function extractBaseTableAlias(AlterableInterface $query) {
// Copied from @see \node_query_node_access_alter
$tables = $query
->getTables();
$base_table = $query
->getMetaData('base_table');
// If the base table is not given, default to one of the node base tables.
if (!$base_table) {
/** @var \Drupal\Core\Entity\Sql\DefaultTableMapping $table_mapping */
$table_mapping = \Drupal::entityTypeManager()
->getStorage('node')
->getTableMapping();
$node_base_tables = $table_mapping
->getTableNames();
foreach ($tables as $table_info) {
if (!$table_info instanceof SelectInterface) {
$table = $table_info['table'];
// Ensure that 'node' and 'node_field_data' are always preferred over
// 'node_revision' and 'node_field_revision'.
if ($table == 'node' || $table == 'node_field_data') {
$base_table = $table;
break;
}
// If one of the node base tables are in the query, add it to the list
// of possible base tables to join against.
if (in_array($table, $node_base_tables)) {
$base_table = $table;
}
}
}
}
if (isset($base_table)) {
// Copied from @see \Drupal\node\NodeGrantDatabaseStorage::alterQuery
foreach ($tables as $table_alias => $tableinfo) {
$table = $tableinfo['table'];
if (!$table instanceof SelectInterface && $table == $base_table) {
return $table_alias;
}
}
}
}