function StylePluginBase::renderGroupingSets

Same name in other branches
  1. 9 core/modules/views/src/Plugin/views/style/StylePluginBase.php \Drupal\views\Plugin\views\style\StylePluginBase::renderGroupingSets()
  2. 10 core/modules/views/src/Plugin/views/style/StylePluginBase.php \Drupal\views\Plugin\views\style\StylePluginBase::renderGroupingSets()
  3. 11.x core/modules/views/src/Plugin/views/style/StylePluginBase.php \Drupal\views\Plugin\views\style\StylePluginBase::renderGroupingSets()

Render the grouping sets.

Plugins may override this method if they wish some other way of handling grouping.

Parameters

$sets: An array keyed by group content containing the grouping sets to render. Each set contains the following associative array:

  • group: The group content.
  • level: The hierarchical level of the grouping.
  • rows: The result rows to be rendered in this group..

Return value

array Render array of grouping sets.

1 call to StylePluginBase::renderGroupingSets()
StylePluginBase::render in core/modules/views/src/Plugin/views/style/StylePluginBase.php
Render the display in this style.

File

core/modules/views/src/Plugin/views/style/StylePluginBase.php, line 490

Class

StylePluginBase
Base class for views style plugins.

Namespace

Drupal\views\Plugin\views\style

Code

public function renderGroupingSets($sets) {
    $output = [];
    $theme_functions = $this->view
        ->buildThemeFunctions($this->groupingTheme);
    foreach ($sets as $set) {
        $level = isset($set['level']) ? $set['level'] : 0;
        $row = reset($set['rows']);
        // Render as a grouping set.
        if (is_array($row) && isset($row['group'])) {
            $single_output = [
                '#theme' => $theme_functions,
                '#view' => $this->view,
                '#grouping' => $this->options['grouping'][$level],
                '#rows' => $set['rows'],
            ];
        }
        else {
            if ($this->usesRowPlugin()) {
                foreach ($set['rows'] as $index => $row) {
                    $this->view->row_index = $index;
                    $set['rows'][$index] = $this->view->rowPlugin
                        ->render($row);
                }
            }
            $single_output = $this->renderRowGroup($set['rows']);
        }
        $single_output['#grouping_level'] = $level;
        $single_output['#title'] = $set['group'];
        $output[] = $single_output;
    }
    unset($this->view->row_index);
    return $output;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.