protected function HelpSearch::prepareResults in Drupal 10
Same name and namespace in other branches
- 8 core/modules/help_topics/src/Plugin/Search/HelpSearch.php \Drupal\help_topics\Plugin\Search\HelpSearch::prepareResults()
- 9 core/modules/help_topics/src/Plugin/Search/HelpSearch.php \Drupal\help_topics\Plugin\Search\HelpSearch::prepareResults()
Prepares search results for display.
Parameters
\Drupal\Core\Database\StatementInterface $found: Results found from a successful search query execute() method.
Return value
array List of search result render arrays, with links, snippets, etc.
File
- core/
modules/ help_topics/ src/ Plugin/ Search/ HelpSearch.php, line 275
Class
- HelpSearch
- Handles searching for help using the Search module index.
Namespace
Drupal\help_topics\Plugin\SearchCode
protected function prepareResults(StatementInterface $found) {
$results = [];
$plugins = [];
$languages = [];
$keys = $this
->getKeywords();
foreach ($found as $item) {
$section_plugin_id = $item->section_plugin_id;
if (!isset($plugins[$section_plugin_id])) {
$plugins[$section_plugin_id] = $this
->getSectionPlugin($section_plugin_id);
}
if ($plugins[$section_plugin_id]) {
$langcode = $item->langcode;
if (!isset($languages[$langcode])) {
$languages[$langcode] = $this->languageManager
->getLanguage($item->langcode);
}
$topic = $plugins[$section_plugin_id]
->renderTopicForSearch($item->topic_id, $languages[$langcode]);
if ($topic) {
if (isset($topic['cacheable_metadata'])) {
$this
->addCacheableDependency($topic['cacheable_metadata']);
}
$results[] = [
'title' => $topic['title'],
'link' => $topic['url']
->toString(),
'snippet' => search_excerpt($keys, $topic['title'] . ' ' . $topic['text'], $item->langcode),
'langcode' => $item->langcode,
];
}
}
}
return $results;
}