You are here

public function Table::setCell in Views Aggregator Plus 8

Render and set a raw value on the table cell in specified column and row.

Parameters

object $field_handler: The field handler associated with the table column being requested.

int $row_num: The result row number. Must be specified.

mixed $new_values: A single or array of values to set. This should be the raw value(s), otherwise sorting may not work properly.

string $separator: The separator to use, when $new_values is an array.

Return value

mixed The rendered value.

1 call to Table::setCell()
Table::setAggregatedGroupValues in src/Plugin/views/style/Table.php
Write the aggregated results back into the View's rendered results.

File

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

Class

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

Namespace

Drupal\views_aggregator\Plugin\views\style

Code

public function setCell($field_handler, $row_num, $new_values, $separator) {
  $rendered_value = FALSE;
  if (isset($field_handler->options['entity_field'])) {
    $field_name = $field_handler->options['entity_field'];
  }
  else {
    $field_name = $field_handler->options['id'];
  }

  // Check, whether we need to aggregate and compress or not.
  if (isset($this->options['group_aggregation']['group_aggregation_results'])) {
    $group_aggregation_results = $this->options['group_aggregation']['group_aggregation_results'];
  }
  else {
    $group_aggregation_results = 0;
  }

  // The webform submission id comes in as views_handler_field_numeric, so all
  // we have to detect it is its name, i.e. 'sid'.
  $is_webform_value = $field_name == 'sid' || $this
    ->isWebformNumeric($field_handler);

  // Depending on the aggregation function applied, default rendering may be
  // inappropriate. For instance "Trains (4)" cannot be rendered numerically.
  if ($is_renderable = $this
    ->isRenderable($field_name, FALSE)) {
    if ($is_webform_value) {
      $rendered_value = $this
        ->renderNewWebformValue($field_handler, $row_num, $new_values, $separator);
    }
    else {
      $rendered_value = $this
        ->renderNewValue($field_handler, $row_num, $new_values, $separator);
    }
  }
  elseif ($is_webform_value) {
    $rendered_value = $new_values;
  }
  if ($rendered_value === FALSE && !$is_webform_value) {
    $rendered_value = is_array($new_values) ? implode($separator, $new_values) : $new_values;
  }
  if ($group_aggregation_results == 0) {
    return $this->rendered_fields[$row_num][$field_handler->options['id']] = $rendered_value;
  }
  else {
    return $rendered_value;
  }
}