Hi,
if I add a addWhere() to the query object in hook_views_query_alter(), my items get filtered like desired in the views pager pages. But the number of the items is broken then. There not shown 10 items anymore. But 10 items minus the number of filtered items. I have used the following code to filter the items:
/**
* Implements hook_views_query_alter().
*/
function permissions_by_term_views_query_alter(ViewExecutable $view, QueryPluginBase $query) {
$query = $view->getQuery();
$accessCheck = \Drupal::service('permissions_by_term.access_check');
if (!$accessCheck->canUserBypassAllAccessChecks()) {
$allowed_nids = $accessCheck->getAllowedNidsByCurrentUsersUid();
if (!empty($allowed_nids) && in_array('node_field_data', array_keys($query->relationships))) {
$view->query->addWhere('pbt', 'node_field_data.nid', $allowed_nids, 'IN');
}
}
return $view;
}
What am I doing wrong? How can I ensure to have always the pre-defined number of items on each pager page?