The method that builds the search results is SearchController::view()
, which contains the following code.
$results = array();
if ($request->query->has('keys')) {
if ($plugin->isSearchExecutable()) {
// Log the search.
if ($this->config('search.settings')->get('logging')) {
$this->logger->notice('Searched %type for %keys.', array('%keys' => $keys, '%type' => $entity->label()));
}
// Collect the search results.
$results = $plugin->buildResults();
}
else {
// The search not being executable means that no keywords or other
// conditions were entered.
drupal_set_message($this->t('Please enter some keywords.'), 'error');
}
}
if (count($results)) {
$build['search_results_title'] = array(
'#markup' => '<h2>' . $this->t('Search results') . '</h2>',
);
}
$build['search_results'] = array(
'#theme' => array('item_list__search_results__' . $plugin->getPluginId(), 'item_list__search_results'),
'#items' => $results,
'#empty' => array(
'#markup' => '<h3>' . $this->t('Your search yielded no results.') . '</h3>',
),
'#list_type' => 'ol',
'#context' => array(
'plugin' => $plugin->getPluginId(),
),
);
So, you can use template_preprocess_item_list(&$variables)
, checking that $variables['#context']['plugin']
is set. (I am not sure about using template_preprocess_item_list__search_results(&$variables)
, since I have never tried using such preprocess function.)
The $plugin->buildResults()
method called from SearchController::view()
just builds the results as array of items themed with search_result.
$results = $this->execute();
$built = array();
foreach ($results as $result) {
$built[] = array(
'#theme' => 'search_result',
'#result' => $result,
'#plugin_id' => $this->getPluginId(),
);
}