Same name and namespace in other branches
  1. 7.x-3.x plugins/QuickViewContent.inc \QuickViewContent::render()

Overrides QuickContentRenderableInterface::render

File

src/Plugin/QuickContent/QuickViewContent.php, line 110

Class

QuickViewContent
Class for tab content of type "view" - this is for rendering a view as tab content. @QuicktabFormat{ id = "quickviewcontent" }

Namespace

Drupal\quicktabs\Plugin\QuickContent

Code

public function render($hide_empty = FALSE, $args = array()) {
    if (!empty($args)) {
        // The args have been passed in from an ajax request. We use Views' own
        // ajax functionality to get the view.
        // The first element of the args array is the qt_name, which we don't need
        // for this content type.
        array_shift($args);
        // The order of these arguments corresponds to the array returned in
        // $this->getAjaxKeys().
        $_REQUEST['view_name'] = array_shift($args);
        $_REQUEST['view_display_id'] = array_shift($args);
        $_REQUEST['view_dom_id'] = array_shift($args);
        $view_path = array_shift($args);
        $_REQUEST['view_path'] = rawurldecode($view_path);
        if (!empty($args)) {
            $view_args = array_shift($args);
            $_REQUEST['view_args'] = rawurldecode($view_args);
        }
        module_load_include('inc', 'views', 'includes/ajax');
        $view = views_ajax();
        foreach ($view['#commands'] as $command) {
            if ($command['command'] == 'insert') {
                return array(
                    '#markup' => trim($command['data']),
                );
            }
        }
        return array();
    }
    // Non-ajax rendering of a view.
    if ($this->rendered_content) {
        return $this->rendered_content;
    }
    $item = $this->settings;
    $output = array();
    if (isset($item['vid'])) {
        if (\Drupal::moduleHandler()->moduleExists('views')) {
            $view = views_get_view($item['vid']);
            if ($view) {
                if ($view->access($item['display'])) {
                    $view->set_display($item['display']);
                    $view->set_arguments($item['actual_args']);
                    $view_output = $view->preview();
                    if (!empty($view->result) || $view->display_handler
                        ->get_option('empty') || !empty($view->style_plugin->definition['even empty'])) {
                        $output['#markup'] = $view_output;
                    }
                }
                elseif (!$hide_empty) {
                    $output['#markup'] = theme('quicktabs_tab_access_denied', array(
                        'tab' => $item,
                    ));
                }
                if ($this->settings['use_title']) {
                    $this->title = $view->get_title();
                }
                $view->destroy();
            }
        }
        elseif (!$hide_empty) {
            $output['#markup'] = t('Views module is not enabled, cannot display content.');
        }
    }
    $this->rendered_content = $output;
    return $output;
}