You are here

public function views_plugin_display_attachment::attach_to in Views (for Drupal 7) 7.3

Same name and namespace in other branches
  1. 6.3 plugins/views_plugin_display_attachment.inc \views_plugin_display_attachment::attach_to()
  2. 6.2 plugins/views_plugin_display_attachment.inc \views_plugin_display_attachment::attach_to()

Attach to another view.

Overrides views_plugin_display::attach_to

File

plugins/views_plugin_display_attachment.inc, line 261
Definition of views_plugin_display_attachment.

Class

views_plugin_display_attachment
The plugin that handles an attachment display.

Code

public 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') && isset($this->view->exposed_input) ? $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_output = $view
    ->execute_display($this->display->id, $args);
  $attachment = '';
  if ($view->display_handler
    ->get_option('show_title') && $view->display_handler
    ->get_option('title')) {
    if ($view->display_handler
      ->get_option('show_title_empty') || !empty($view->result)) {
      $attachment .= theme('html_tag', array(
        'element' => array(
          '#tag' => 'h2',
          '#value' => $view->display_handler
            ->get_option('title'),
        ),
      ));
    }
  }
  $attachment .= $attachment_output;
  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();
}