You are here

public function RestExport::initDisplay in Drupal 9

Same name and namespace in other branches
  1. 8 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 155

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);

  // If the default 'json' format is not selected as a format option in the
  // view display, fallback to the first format available for the default.
  if (!empty($options['style']['options']['formats']) && !isset($options['style']['options']['formats'][$this
    ->getContentType()])) {
    $default_format = reset($options['style']['options']['formats']);
    $this
      ->setContentType($default_format);
  }

  // Only use the requested content type if it's not 'html'. This allows
  // still falling back to the default for things like views preview.
  $request_content_type = $this->view
    ->getRequest()
    ->getRequestFormat();
  if ($request_content_type !== 'html') {
    $this
      ->setContentType($request_content_type);
  }
  $this
    ->setMimeType($this->view
    ->getRequest()
    ->getMimeType($this
    ->getContentType()));
}