protected function NodeSearch::indexNode in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/node/src/Plugin/Search/NodeSearch.php \Drupal\node\Plugin\Search\NodeSearch::indexNode()
Indexes a single node.
Parameters
\Drupal\node\NodeInterface $node: The node to index.
1 call to NodeSearch::indexNode()
- NodeSearch::updateIndex in core/
modules/ node/ src/ Plugin/ Search/ NodeSearch.php - Updates the search index for this plugin.
File
- core/
modules/ node/ src/ Plugin/ Search/ NodeSearch.php, line 450 - Contains \Drupal\node\Plugin\Search\NodeSearch.
Class
- NodeSearch
- Handles searching for node entities using the Search module index.
Namespace
Drupal\node\Plugin\SearchCode
protected function indexNode(NodeInterface $node) {
$languages = $node
->getTranslationLanguages();
$node_render = $this->entityManager
->getViewBuilder('node');
foreach ($languages as $language) {
$node = $node
->getTranslation($language
->getId());
// Render the node.
$build = $node_render
->view($node, 'search_index', $language
->getId());
unset($build['#theme']);
// Add the title to text so it is searchable.
$build['search_title'] = [
'#prefix' => '<h1>',
'#plain_text' => $node
->label(),
'#suffix' => '</h1>',
'#weight' => -1000,
];
$text = $this->renderer
->renderPlain($build);
// Fetch extra data normally not visible.
$extra = $this->moduleHandler
->invokeAll('node_update_index', [
$node,
]);
foreach ($extra as $t) {
$text .= $t;
}
// Update index, using search index "type" equal to the plugin ID.
search_index($this
->getPluginId(), $node
->id(), $language
->getId(), $text);
}
}