function hook_search_by_page_details in Search by Page 8
Return details about an indexed path (required sub-module hook).
This hook is invoked after a search, to get full information about what to display.
This hook is also invoked during search indexing to get the page title which is added to the indexed text. In this case, $keys will be null, and the module can also return rendered content to be indexed, if desired.
Parameters
$id: The ID corresponding to the path. This is the ID number you returned in hook_search_by_page_paths(), for this path.
$environment: ID of environment currently being indexed or searched.
$keys: The keywords being searched for (useful in extracting a snippet). NULL indicates this call is for search indexing.
Return value
One of the following:
- If for some reason this path should not be displayed or indexed, return NULL or zero.
- If $keys is NULL, return an associative array for search
indexing, with the following elements:
- title: Page title.
- content: (optional) Override of the page content, to avoid standard Drupal rendering.
- If $keys is not NULL, return an associative array of fields suitable
for display on the search results screen for this path. See the Core
documentation for hook_search() for a list of what the fields are. Some
notes on the fields:
- title: Required.
- link: Should be omitted (it is handled by the main search_by_page module.
- snippet: Suggested. See also \Drupal::service('search_by_page.settings')->excerpt().
- object: An object (such as node, user, or file object) related to the results.
See also
4 functions implement hook_search_by_page_details()
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
- search_by_page_attach_search_by_page_details in search_by_page_attach/
search_by_page_attach.module - Implements Search by Page hook_search_by_page_details().
- search_by_page_nodes_search_by_page_details in search_by_page_nodes/
search_by_page_nodes.module - Implements Search by Page hook_search_by_page_details().
- search_by_page_paths_search_by_page_details in search_by_page_paths/
search_by_page_paths.module - Implements Search by Page hook_search_by_page_details().
- search_by_page_users_search_by_page_details in search_by_page_users/
search_by_page_users.module - Implements Search by Page hook_search_by_page_details().
2 invocations of hook_search_by_page_details()
- search_by_page_search_execute in ./
search_by_page.module - Implements hook_search_execute().
- search_by_page_update_index in ./
search_by_page.module - Implements hook_update_index().
File
- ./
search_by_page.api.php, line 134 - Search by Page module API.
Code
function hook_search_by_page_details($id, $environment, $keys = NULL) {
$node = Drupal\node\Entity\Node::load($id);
$type = Drupal\node\Entity\NodeType::load($node);
return array(
'type' => Html::escape($type->name),
'title' => search_by_page_strip_tags($node->title, $environment),
'user' => theme('username', [
'account' => $node,
]),
'date' => $node->changed,
'extra' => $node
->get('extra')->value,
'snippet' => \Drupal::service('search_by_page.settings')
->excerpt($keys, search_by_page_strip_tags($node
->get('body')[LANGUAGE_NONE][0]->value, $environment)),
);
}