You are here

public function ComplexGrouping::renderGroupingSets in Views Complex Grouping 8

Render the grouping sets.

Overrides StylePluginBase::renderGroupingSets

File

src/Plugin/views/style/ComplexGrouping.php, line 226

Class

ComplexGrouping
Class ComplexGrouping.

Namespace

Drupal\views_complex_grouping\Plugin\views\style

Code

public function renderGroupingSets($sets) {
  $output = [];
  $branch = 0;
  $theme_functions = $this->view
    ->buildThemeFunctions($this->complexGroupingTheme);
  foreach ($sets as $set) {
    $branch++;
    $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],
        '#grouping_branch' => $branch,
        '#rows' => $set['rows'],
        '#fields' => $set['fields'],
      ];
    }
    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'] = $this->options['grouping'][$level];
      $single_output['#grouping_branch'] = $branch;
      $single_output['#fields'] = $set['fields'];
    }
    $single_output['#grouping_level'] = $level + 1;
    $single_output['#title'] = $set['group'];
    $output[] = $single_output;
  }
  unset($this->view->row_index);
  return $output;
}