function RestExport::initDisplay

Same name in other branches
  1. 9 core/modules/rest/src/Plugin/views/display/RestExport.php \Drupal\rest\Plugin\views\display\RestExport::initDisplay()
  2. 8.9.x core/modules/rest/src/Plugin/views/display/RestExport.php \Drupal\rest\Plugin\views\display\RestExport::initDisplay()
  3. 11.x core/modules/rest/src/Plugin/views/display/RestExport.php \Drupal\rest\Plugin\views\display\RestExport::initDisplay()

Overrides DisplayPluginBase::initDisplay

File

core/modules/rest/src/Plugin/views/display/RestExport.php, line 157

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.