You are here

protected function Table::compressGroupedResults in Views Aggregator Plus 8

Removes no longer needed View result rows from the set.

Parameters

array $groups: Groups of aggregated rows.

1 call to Table::compressGroupedResults()
Table::preRender in src/Plugin/views/style/Table.php
Note that this class being a views_plugin, rather than a views_handler, it does not have a post_execute() function.

File

src/Plugin/views/style/Table.php, line 547

Class

Table
Style plugin to render each item as a row in a table.

Namespace

Drupal\views_aggregator\Plugin\views\style

Code

protected function compressGroupedResults(array $groups) {
  $rows_per_group = 0;
  foreach ($groups as $rows) {
    if (isset($rows)) {
      $rows_per_group = count($rows);
    }
    $is_first = TRUE;
    foreach ($rows as $num => $row) {

      // The aggregated row is the first of each group. Destroy the others.
      if (!$is_first) {
        unset($this->rendered_fields[$num]);
        unset($this->view->result[$num]);
      }
      $is_first = FALSE;
    }
  }

  // Reindex the result arrays.
  $this->rendered_fields = array_values(array_filter($this->rendered_fields));
  $this->view->result = array_values(array_filter($this->view->result));

  // Used for Views Bulk Operations to rename the checkboxes.
  $field_handlers = $this->view->field;
  $moduleHandler = \Drupal::service('module_handler');
  foreach ($field_handlers as $field_name => $handler) {
    if ($handler instanceof BulkForm || $moduleHandler
      ->moduleExists('views_bulk_operations') && is_a($handler, '\\Drupal\\views_bulk_operations\\Plugin\\views\\field\\ViewsBulkOperationsBulkForm')) {
      foreach ($this->rendered_fields as $num => $row) {
        $this->rendered_fields[$num][$field_name] = ViewsRenderPipelineMarkup::create('<!--form-item-' . $field_name . '--' . $num . '-->');
      }
    }
  }
}