You are here

public function RestExport::initDisplay in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/rest/src/Plugin/views/display/RestExport.php \Drupal\rest\Plugin\views\display\RestExport::initDisplay()

Initializes the display plugin.

Parameters

\Drupal\views\ViewExecutable $view: The views executable.

array $display: The display that will be populated and attached to the view.

array $options: (optional) The options for the display plugin. Defaults to NULL.

Overrides DisplayPluginBase::initDisplay

File

core/modules/rest/src/Plugin/views/display/RestExport.php, line 123
Contains \Drupal\rest\Plugin\views\display\RestExport.

Class

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

Namespace

Drupal\rest\Plugin\views\display

Code

public function initDisplay(ViewExecutable $view, array &$display, array &$options = NULL) {
  parent::initDisplay($view, $display, $options);
  $request_content_type = $this->view
    ->getRequest()
    ->getRequestFormat();

  // Only use the requested content type if it's not 'html'. If it is then
  // default to 'json' to aid debugging.
  // @todo Remove the need for this when we have better content negotiation.
  if ($request_content_type != 'html') {
    $this
      ->setContentType($request_content_type);
  }
  elseif (!empty($options['style']['options']['formats']) && !isset($options['style']['options']['formats'][$this
    ->getContentType()])) {
    $this
      ->setContentType(reset($options['style']['options']['formats']));
  }
  $this
    ->setMimeType($this->view
    ->getRequest()
    ->getMimeType($this->contentType));
}