1.20.x views_plugin_display_attachment.inc views_plugin_display_attachment::attach_to($display_id)

Attach to another view.

Overrides views_plugin_display::attach_to

File

modules/views/plugins/views_plugin_display_attachment.inc, line 212
Contains the attachment display plugin.

Class

views_plugin_display_attachment
The plugin that handles an attachment display.

Code

function attach_to($display_id) {
  $displays = $this->get_option('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->clone_view();
  $view->original_args = $view->args;

  $args = $this->get_option('inherit_arguments') ? $this->view->args : array();
  $view->set_arguments($args);
  $exposed_input = $this->get_option('inherit_exposed_filters') ? $this->view->exposed_input : array();
  $view->set_exposed_input($exposed_input);
  $view->set_display($this->display->id);
  if ($this->get_option('inherit_pager')) {
    $view->display_handler->use_pager = $this->view->display[$display_id]->handler->use_pager();
    $view->display_handler->set_option('pager', $this->view->display[$display_id]->handler->get_option('pager'));
  }

  $attachment = $view->execute_display($this->display->id, $args);

  switch ($this->get_option('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();
}