public function NodeGrantDatabaseStorage::alterQuery in Drupal 10
Same name and namespace in other branches
- 8 core/modules/node/src/NodeGrantDatabaseStorage.php \Drupal\node\NodeGrantDatabaseStorage::alterQuery()
- 9 core/modules/node/src/NodeGrantDatabaseStorage.php \Drupal\node\NodeGrantDatabaseStorage::alterQuery()
File
- core/modules/node/src/NodeGrantDatabaseStorage.php, line 149
Class
- NodeGrantDatabaseStorage
- Defines a storage handler class that handles the node grants system.
Namespace
Drupal\node
Code
public function alterQuery($query, array $tables, $op, AccountInterface $account, $base_table) {
if (!($langcode = $query
->getMetaData('langcode'))) {
$langcode = FALSE;
}
$grants = node_access_grants($op, $account);
$grant_conditions = $this
->buildGrantsQueryCondition($grants);
$grants_exist = count($grant_conditions
->conditions()) > 0;
$is_multilingual = \Drupal::languageManager()
->isMultilingual();
foreach ($tables as $nalias => $tableinfo) {
$table = $tableinfo['table'];
if (!$table instanceof SelectInterface && $table == $base_table) {
$subquery = $this->database
->select('node_access', 'na')
->fields('na', [
'nid',
]);
if ($grants_exist) {
$subquery
->condition($grant_conditions);
}
$subquery
->condition('na.grant_' . $op, 1, '>=');
if ($is_multilingual) {
if ($langcode === FALSE) {
$subquery
->condition('na.fallback', 1, '=');
}
else {
$subquery
->condition('na.langcode', $langcode, '=');
}
}
$field = 'nid';
$subquery
->where("[{$nalias}].[{$field}] = [na].[nid]");
$query
->exists($subquery);
}
}
}