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

hass’s picture

Issue summary: View changes
hass’s picture

Issue summary: View changes
hass’s picture

Issue summary: View changes
hass’s picture

Issue summary: View changes
hass’s picture

Issue summary: View changes
sun’s picture

hass’s picture

markhalliwell’s picture

Status: Closed (duplicate) » Active
star-szr’s picture

Category: Bug report » Support request
markhalliwell’s picture

Status: Active » Closed (duplicate)

Agreed with @Cottser, the reason is: google_analytics_item_list__search_results is missing the _preprocess_ portion:

google_analytics_item_list__search_results // Change this
google_analytics_preprocess_item_list__search_results  // To this