function search_by_page_nodes_search_by_page_paths in Search by Page 8
Implements Search by Page hook_search_by_page_paths().
Returns a list of all the nodes that should be indexed.
File
- search_by_page_nodes/
search_by_page_nodes.module, line 19 - Module file for Search by Page Nodes, a sub-module for Search by Page.
Code
function search_by_page_nodes_search_by_page_paths($environment) {
// What node types do they want to index?
$typelist = search_by_page_setting_get('search_by_page_nodes_types_indexed', $environment, []);
if (!is_array($typelist) || !count($typelist)) {
return [];
}
// This variable comes from a checkbox array form element. So it
// gives us an array like 'page' => 'page', 'story' => 0
// meaning page should be indexed, but not story
// so pick out the ones to actually index
$toindex = [];
foreach ($typelist as $key => $item) {
if ($item) {
$toindex[] = $key;
}
}
if (!count($toindex)) {
return [];
}
// Find all published nodes of those types, and build array of paths
// Note that we don't want to check for access permissions here! We
// want to index everything, independent of access rights. Access
// permission checking is done during the search step -- see
// hook_search_by_page_query_modify() implementation below. This is the same
// procedure followed in node_search(), which performs searching for
// the core Search module, and node_update_index(), which indexes
// everything for Search without access checks.
$res = \Drupal::database()
->query('SELECT n.nid, n.language FROM {node} n WHERE n.status=1 AND n.type IN (:toindex)', [
':toindex' => $toindex,
])
->fetchAll();
$role = search_by_page_setting_get('search_by_page_nodes_role', $environment, AccountInterface::ANONYMOUS_ROLE);
$min_time = search_by_page_setting_get('search_by_page_nodes_min_time', $environment, 1);
$max_time = search_by_page_setting_get('search_by_page_nodes_max_time', $environment, 0);
$languageManager = new \Drupal\Core\Language\LanguageManager();
$langs = $languageManager
->getLanguages();
$langs = array_keys($langs);
$ret = [];
foreach ($res as $item) {
$stuff = [
'id' => $item->nid,
'role' => $role,
'min_time' => $min_time,
'max_time' => $max_time,
];
if ($item->language && $item->language != LANGUAGE_NONE) {
$stuff['languages'] = [
$item->language,
];
}
else {
// language-neutral - index in all languages
$stuff['languages'] = $langs;
}
$ret['node/' . $item->nid] = $stuff;
}
return $ret;
}