You are here

public static function AutocompletionCallback::buildResponse in Search Autocomplete 8

Same name and namespace in other branches
  1. 2.x src/Plugin/views/display/AutocompletionCallback.php \Drupal\search_autocomplete\Plugin\views\display\AutocompletionCallback::buildResponse()

Builds up a response with the rendered view as content.

Parameters

string $view_id: The view ID.

string $display_id: The display ID.

array $args: (optional) The arguments of the view.

Return value

\Symfony\Component\HttpFoundation\Response The built response.

Overrides ResponseDisplayPluginInterface::buildResponse

File

src/Plugin/views/display/AutocompletionCallback.php, line 123

Class

AutocompletionCallback
The plugin that handles Data response callbacks for REST resources.

Namespace

Drupal\search_autocomplete\Plugin\views\display

Code

public static function buildResponse($view_id, $display_id, array $args = []) {
  $build = static::buildBasicRenderable($view_id, $display_id, $args);

  // @var \Drupal\Core\Render\RendererInterface $renderer.
  $renderer = Drupal::service('renderer');
  $output = $renderer
    ->renderRoot($build);
  $response = new CacheableResponse($output, 200);
  $cache_metadata = CacheableMetadata::createFromRenderArray($build);
  $response
    ->addCacheableDependency($cache_metadata);
  $response->headers
    ->set('Content-type', 'application/json');
  return $response;
}