You are here

public function SlickGrouping::renderGroupingSets in Slick Views 8.2

Overrides StylePluginBase::renderGroupingSets().

See also

https://www.drupal.org/node/2639300

File

src/Plugin/views/style/SlickGrouping.php, line 177

Class

SlickGrouping
Slick style plugin with grouping support.

Namespace

Drupal\slick_views\Plugin\views\style

Code

public function renderGroupingSets($sets) {
  $output = [];
  $grouping = empty($this->options['grouping']) ? [] : array_filter($this->options['grouping']);
  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' => $this->view
          ->buildThemeFunctions($this->groupingTheme),
        '#view' => $this->view,
        '#grouping' => $grouping[$level],
        '#rows' => $set['rows'],
      ];
    }
    else {
      $slick = $this
        ->renderRowGroup($set['rows'], $level);

      // Views leaves the first grouping header to the style plugin.
      if (!empty($grouping) && $level == 0) {
        if (empty($this->options['grouping_optionset'])) {
          $content[0] = $slick;
          $content[0]['#prefix'] = '<h2 class="view-grouping-header">' . $set['group'] . '</h2>';
          $single_output = $content;
          $single_output['#theme_wrappers'][] = 'container';
          $single_output['#attributes']['class'][] = 'view-grouping';
        }
        else {
          $single_output = $slick;
        }
      }
      else {
        $single_output = $slick;
      }
    }
    $single_output['#grouping_level'] = $level;
    $single_output['#title'] = $set['group'];
    $output[] = $single_output;
  }
  return $output;
}