function views_plugin_display_attachment::attach_to

Same name in other branches
  1. 7.x-3.x 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 206

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);
    $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();
}