function DisplayPluginBase::initDisplay

Same name and namespace in other branches
  1. 8.9.x core/modules/views/src/Plugin/views/display/DisplayPluginBase.php \Drupal\views\Plugin\views\display\DisplayPluginBase::initDisplay()
  2. 10 core/modules/views/src/Plugin/views/display/DisplayPluginBase.php \Drupal\views\Plugin\views\display\DisplayPluginBase::initDisplay()
  3. 11.x core/modules/views/src/Plugin/views/display/DisplayPluginBase.php \Drupal\views\Plugin\views\display\DisplayPluginBase::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 DisplayPluginInterface::initDisplay

1 call to DisplayPluginBase::initDisplay()
RestExport::initDisplay in core/modules/rest/src/Plugin/views/display/RestExport.php
1 method overrides DisplayPluginBase::initDisplay()
RestExport::initDisplay in core/modules/rest/src/Plugin/views/display/RestExport.php

File

core/modules/views/src/Plugin/views/display/DisplayPluginBase.php, line 150

Class

DisplayPluginBase
Base class for views display plugins.

Namespace

Drupal\views\Plugin\views\display

Code

public function initDisplay(ViewExecutable $view, array &$display, array &$options = NULL) {
  $this->view = $view;
  // Load extenders as soon as possible.
  $display['display_options'] += [
    'display_extenders' => [],
  ];
  $this->extenders = [];
  if ($extenders = Views::getEnabledDisplayExtenders()) {
    $manager = Views::pluginManager('display_extender');
    $display_extender_options = $display['display_options']['display_extenders'];
    foreach ($extenders as $extender) {
      /** @var \Drupal\views\Plugin\views\display_extender\DisplayExtenderPluginBase $plugin */
      if ($plugin = $manager->createInstance($extender)) {
        $extender_options = isset($display_extender_options[$plugin->getPluginId()]) ? $display_extender_options[$plugin->getPluginId()] : [];
        $plugin->init($this->view, $this, $extender_options);
        $this->extenders[$extender] = $plugin;
      }
    }
  }
  $this->setOptionDefaults($this->options, $this->defineOptions());
  $this->display =& $display;
  // Track changes that the user should know about.
  $changed = FALSE;
  if (!isset($options) && isset($display['display_options'])) {
    $options = $display['display_options'];
  }
  if ($this->isDefaultDisplay() && isset($options['defaults'])) {
    unset($options['defaults']);
  }
  $skip_cache = \Drupal::config('views.settings')->get('skip_cache');
  if (!$skip_cache) {
    $cid = 'views:unpack_options:' . hash('sha256', serialize([
      $this->options,
      $options,
    ])) . ':' . \Drupal::languageManager()->getCurrentLanguage()
      ->getId();
    if (empty(static::$unpackOptions[$cid])) {
      $cache = \Drupal::cache('data')->get($cid);
      if (!empty($cache->data)) {
        $this->options = $cache->data;
      }
      else {
        $this->unpackOptions($this->options, $options);
        \Drupal::cache('data')->set($cid, $this->options, Cache::PERMANENT, $this->view->storage
          ->getCacheTags());
      }
      static::$unpackOptions[$cid] = $this->options;
    }
    else {
      $this->options = static::$unpackOptions[$cid];
    }
  }
  else {
    $this->unpackOptions($this->options, $options);
  }
  // Mark the view as changed so the user has a chance to save it.
  if ($changed) {
    $this->view->changed = TRUE;
  }
}

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