You are here

public function GssSearchController::view in Google Site Search 8

Creates a render array for the search page.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The request object.

\Drupal\search\SearchPageInterface $entity: The search page entity.

Return value

array The search form and search results build array.

Overrides SearchController::view

File

src/Controller/GssSearchController.php, line 17

Class

GssSearchController
Route controller for GSS Search.

Namespace

Drupal\gss\Controller

Code

public function view(Request $request, SearchPageInterface $entity) {

  /** @var \Drupal\gss\Plugin\Search\Search $plugin */
  $plugin = $entity
    ->getPlugin();
  $build = parent::view($request, $entity);

  // Alter the pager to set # of page links.
  $build['pager']['#quantity'] = $plugin
    ->getPagerSize();

  // Alter the pager to not show last link. API total results is unreliable,
  // so "last" link is problematic.
  $build['pager']['#tags'][4] = ' ';
  return [
    '#theme_wrappers' => [
      'container__gss_search_page',
    ],
    '#cache' => $build['#cache'],
    '#title' => $build['#title'],
    '#plugin' => $plugin,
    'search_form' => $build['search_form'],
    'search_results_title' => @$build['search_results_title'],
    'links' => $plugin
      ->getSearchOptions($request),
    'labels' => $plugin
      ->getLabels($request),
    'search_results' => $build['search_results'],
    'pager' => $build['pager'],
  ];
}