function search_by_page_nodes_search_by_page_query_modify in Search by Page 8
Implements Search by Page hook_search_by_page_query_modify().
Adds an access permission check to the search query.
File
- search_by_page_nodes/
search_by_page_nodes.module, line 92 - Module file for Search by Page Nodes, a sub-module for Search by Page.
Code
function search_by_page_nodes_search_by_page_query_modify($environment, $query) {
$cond = new \Drupal\Core\Database\Query\Condition('AND');
if (!\Drupal::currentUser()
->hasPermission('access content')) {
// This user cannot access content, so don't bother with the query
// mods, they should not see anything from this module.
$cond
->where('0=1');
return $cond;
}
// Join to the node table and mark it as a node access query.
$query
->leftJoin('node', 'sbpn_n', 'sbpn_n.nid = sp.modid');
$query
->addTag('node_access');
// Make sure also only to allow published content.
$cond = new \Drupal\Core\Database\Query\Condition('AND');
$cond
->condition('sbpn_n.status', 1);
return $cond;
}