You are here

public function Attachment::attachTo in Views (for Drupal 7) 8.3

Attach to another view.

Overrides DisplayPluginBase::attachTo

File

lib/Drupal/views/Plugin/views/display/Attachment.php, line 233
Definition of Drupal\views\Plugin\views\display\Attachment.

Class

Attachment
The plugin that handles an attachment display.

Namespace

Drupal\views\Plugin\views\display

Code

public function attachTo($display_id) {
  $displays = $this
    ->getOption('displays');
  if (empty($displays[$display_id])) {
    return;
  }
  if (!$this
    ->access()) {
    return;
  }

  // Get a fresh view because our current one has a lot of stuff on it because it's
  // already been executed.
  $view = $this->view
    ->cloneView();
  $args = $this
    ->getOption('inherit_arguments') ? $this->view->args : array();
  $view
    ->setArguments($args);
  $view
    ->setDisplay($this->display['id']);
  if ($this
    ->getOption('inherit_pager')) {
    $view->display_handler->usesPager = $this->view->display[$display_id]->handler
      ->usesPager();
    $view->display_handler
      ->setOption('pager', $this->view->display[$display_id]->handler
      ->getOption('pager'));
  }
  $attachment = $view
    ->executeDisplay($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;
  }
  $view
    ->destroy();
}