You are here

public function Attachment::attachTo in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/views/src/Plugin/views/display/Attachment.php \Drupal\views\Plugin\views\display\Attachment::attachTo()

Allows displays to attach to other views.

Parameters

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

string $display_id: The display to attach to.

array $build: The parent view render array.

Overrides DisplayPluginBase::attachTo

File

core/modules/views/src/Plugin/views/display/Attachment.php, line 237

Class

Attachment
The plugin that handles an attachment display.

Namespace

Drupal\views\Plugin\views\display

Code

public function attachTo(ViewExecutable $view, $display_id, array &$build) {
  $displays = $this
    ->getOption('displays');
  if (empty($displays[$display_id])) {
    return;
  }
  if (!$this
    ->access()) {
    return;
  }
  $args = $this
    ->getOption('inherit_arguments') ? $this->view->args : [];
  $view
    ->setArguments($args);
  $view
    ->setDisplay($this->display['id']);
  if ($this
    ->getOption('inherit_pager')) {
    $view->display_handler->usesPager = $this->view->displayHandlers
      ->get($display_id)
      ->usesPager();
    $view->display_handler
      ->setOption('pager', $this->view->displayHandlers
      ->get($display_id)
      ->getOption('pager'));
  }
  $attachment = $view
    ->buildRenderable($this->display['id'], $args);
  switch ($this
    ->getOption('attachment_position')) {
    case 'before':
      $this->view->attachment_before[] = $attachment;
      break;
    case 'after':
      $this->view->attachment_after[] = $attachment;
      break;
    case 'both':
      $this->view->attachment_before[] = $attachment;
      $this->view->attachment_after[] = $attachment;
      break;
  }
}