You are here

public function DisplayPluginBase::buildRenderable in Zircon Profile 8

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

Builds a renderable array of the view.

Note: This does not yet contain the executed view, but just the loaded view executable.

Parameters

array $args: (optional) Arguments of the view.

bool $cache: (optional) Specify FALSE in order to opt out of render caching.

Return value

array The render array of a view.

Overrides DisplayPluginInterface::buildRenderable

File

core/modules/views/src/Plugin/views/display/DisplayPluginBase.php, line 2327
Contains \Drupal\views\Plugin\views\display\DisplayPluginBase.

Class

DisplayPluginBase
Base class for views display plugins.

Namespace

Drupal\views\Plugin\views\display

Code

public function buildRenderable(array $args = [], $cache = TRUE) {
  $this->view->element += [
    '#type' => 'view',
    '#name' => $this->view->storage
      ->id(),
    '#display_id' => $this->display['id'],
    '#arguments' => $args,
    '#embed' => FALSE,
    '#view' => $this->view,
    '#cache_properties' => [
      '#view_id',
      '#view_display_show_admin_links',
      '#view_display_plugin_id',
    ],
  ];
  if ($cache) {
    $this->view->element['#cache'] += [
      'keys' => [],
    ];

    // Places like \Drupal\views\ViewExecutable::setCurrentPage() set up an
    // additional cache context.
    $this->view->element['#cache']['keys'] = array_merge([
      'views',
      'display',
      $this->view->element['#name'],
      $this->view->element['#display_id'],
    ], $this->view->element['#cache']['keys']);
    $this
      ->applyDisplayCachablityMetadata($this->view->element);
  }
  else {

    // Remove the cache keys, to ensure render caching is not triggered. We
    // don't unset the other #cache values, to allow cacheability metadata to
    // still be bubbled.
    unset($this->view->element['#cache']['keys']);
  }
  return $this->view->element;
}