Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I need the hook google_analytics_item_list__search_results()
, but it looks like this is not executed. It's defined in SearchController::view
in
$build['search_results'] = array(
'#theme' => array('item_list__search_results__' . $plugin->getPluginId(), 'item_list__search_results'),
'#items' => $results,
'#empty' => array(
// @todo Revisit where this help text is added.
'#markup' => '<h3>' . $this->t('Your search yielded no results.') . '</h3>' . search_help('search#noresults', drupal_help_arg()),
),
'#list_type' => 'ol',
'#attributes' => array(
'class' => array(
'search-results',
$plugin->getPluginId() . '-results',
),
),
);
This hook works, but it's tooo general:
function google_analytics_preprocess_item_list(&$variables) {
global $pager_total_items;
krumo(intval($pager_total_items[0]));
krumo($variables);
}
This is what I need, but it does not work:
function google_analytics_item_list__search_results(&$variables) {
global $pager_total_items;
krumo(intval($pager_total_items[0]));
krumo($variables);
}
Any idea what may be wrong?
If you may ask what I really need is - something that calls a hook/function in my module if the search result is rendered and that gives me the number of search items found.
Comments
Comment #1
hass CreditAttribution: hass commentedComment #2
hass CreditAttribution: hass commentedComment #3
hass CreditAttribution: hass commentedComment #4
hass CreditAttribution: hass commentedComment #5
hass CreditAttribution: hass commentedComment #6
sun#939462: Specific preprocess functions for theme hook suggestions are not invoked
Comment #7
hass CreditAttribution: hass commentedComment #8
markhalliwellComment #9
star-szrComment #10
markhalliwellAgreed with @Cottser, the reason is:
google_analytics_item_list__search_results
is missing the_preprocess_
portion: