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

Return value

array

Overrides QuickRenderer::render

Fichier

src/Plugin/QuickRender/QuickQuicktabs.php, line 22

Classe

QuickQuicktabs
Renders the content using the original Quicktabs mechanism of previous versions. Includes support for ajax rendered content.

Namespace

Drupal\quicktabs\Plugin\QuickRender

Code

public function render() {
    $quickset = $this->quickset;
    $render_array = array();
    $active_tab = $quickset->getActiveTab();
    $tabs = $this->build_tablinks($active_tab);
    if ($tabs) {
        $render_array['#attached'] = $this->add_attached();
        $qt_name = $quickset->getName();
        $settings = $quickset->getSettings();
        $contents = $quickset->getContents();
        $render_array['content'] = array(
            '#theme' => 'qt_quicktabs',
            '#options' => array(
                'attributes' => array(
                    'id' => 'quicktabs-' . $qt_name,
                    'class' => 'quicktabs-wrapper quicktabs-style-' . Html::getClass($settings['style']),
                ),
            ),
            'tabs' => array(
                '#theme' => 'qt_quicktabs_tabset',
                '#options' => array(
                    'active' => $active_tab,
                    'style' => Html::getClass($settings['style']),
                ),
                'tablinks' => $tabs,
            ),
            // The main content area, each quicktab container needs a unique id.
'container' => array(
                '#prefix' => '<div id="quicktabs-container-' . $qt_name . '" class="quicktabs_main quicktabs-style-' . Html::getClass($settings['style']) . '">',
                '#suffix' => '</div>',
                'divs' => array(),
            ),
        );
        // If in ajax mode, we'll only be rendering one tab, otherwise all of them.
        if ($settings['ajax']) {
            // check in case of $active_tab=QUICKTABS_DELTA_NONE
            $tabs_to_render = isset($contents[$active_tab]) ? array(
                $active_tab => $contents[$active_tab],
            ) : array();
        }
        else {
            $tabs_to_render = $contents;
        }
        foreach ($tabs_to_render as $key => $tab) {
            if (!empty($tab)) {
                $attribs = array(
                    'id' => 'quicktabs-tabpage-' . $qt_name . '-' . $key,
                    'class' => array(
                        'quicktabs-tabpage',
                        $active_tab == $key ? '' : 'quicktabs-hide',
                    ),
                );
                $render_array['content']['container']['divs'][] = array(
                    '#prefix' => '<div ' . drupal_attributes($attribs) . '>',
                    '#suffix' => '</div>',
                    'content' => $tab->render(),
                );
            }
        }
    }
    return $render_array;
}