You are here

function panopoly_search_views_post_render in Panopoly Search 8.2

Implements hook_views_post_render().

File

./panopoly_search.module, line 143
Hooks for the panopoly_search module.

Code

function panopoly_search_views_post_render(ViewExecutable $view, &$output, CachePluginBase $cache) {
  if (!in_array($view
    ->id(), [
    'panopoly_search_db',
    'panopoly_search_solr',
  ])) {
    return;
  }
  $keys = \Drupal::request()->query
    ->get('keys');
  if (!empty($keys)) {
    $count = count($view->result);
    $title = new TranslatableMarkup('Search results: @count matched %keys', [
      '@count' => \Drupal::translation()
        ->formatPlural($count, '1 item', '@count items'),
      '%keys' => $keys,
    ]);

    // Set the view title.
    $view
      ->setTitle($title);

    // Log the search so it can appear in 'Top search phrases' report.
    \Drupal::logger('search')
      ->notice('Searched %type for %keys.', [
      '%keys' => $keys,
      '%type' => 'Content',
    ]);
  }
}