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

Overrides QuickContentRenderableInterface::render

Fichier

src/Plugin/QuickContent/QuickCallbackContent.php, line 80

Classe

QuickCallbackContent
Class for tab content of type "callback" - this is for rendering the contents of some menu callback function as tab content. @QuicktabFormat{ id = "quickcallbackcontent"

Namespace

Drupal\quicktabs\Plugin\QuickContent

Code

public function render($hide_empty = FALSE, $args = array()) {
    if ($this->rendered_content) {
        return $this->rendered_content;
    }
    $item = $this->settings;
    if (!empty($args)) {
        // The args have been passed in from an ajax request.
        // The first element of the args array is the qt_name, which we don't need
        // for this content type.
        array_shift($args);
        $item['actual_path'] = rawurldecode($args[0]);
        
        //$_GET['q'] = $item['actual_path'];
    }
    $output = array();
    if (isset($item['actual_path'])) {
        // Retain the current page title as we'll need to set it back after
        // calling menu_execute_active_handler().
        $request = \Drupal::request();
        $route_match = \Drupal::routeMatch();
        $page_title = \Drupal::service('title_resolver')->getTitle($request, $route_match);
        $request = \Drupal::service('request_stack');
        $subrequest = Request::create($item['actual_path'], 'GET', $request->query
            ->all(), $request->cookies
            ->all(), array(), $request->server
            ->all());
        $response = \Drupal::service('http_kernel')->handle($subrequest, HttpKernelInterface::SUB_REQUEST);
        
        //$response = menu_execute_active_handler($item['actual_path'], FALSE);
        // Revert the page title.
        if ($this->settings['use_title']) {
            $temp_request = \Drupal::request();
            $temp_route_match = \Drupal::routeMatch();
            $this->title = \Drupal::service('title_resolver')->getTitle($temp_request, $temp_route_match);
        }
        drupal_set_title($page_title);
        if (!is_array($response)) {
            if (is_int($response)) {
                if (MENU_ACCESS_DENIED == $response && !$hide_empty) {
                    $output['#markup'] = theme('quicktabs_tab_access_denied', array(
                        'tab' => $item,
                    ));
                }
                // For any other integer response form the menu callback, we'll just
                // return an empty array.
            }
            else {
                $output = array(
                    '#markup' => $response,
                );
            }
        }
        else {
            $output = $response;
        }
    }
    $this->rendered_content = $output;
    return $output;
}