You are here

protected function Table::renderNewWebformValue in Views Aggregator Plus 8

Returns the rendered representation for a new webform value.

Parameters

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

int $row_num: The result row number.

array $new_values: The raw value(s) to render using the webform's rounding, prefix, suffix.

string $separator: Separator to use between rendered values, when $new_values is an array.

Return value

string The rendered value.

3 calls to Table::renderNewWebformValue()
Table::renderNewValue in src/Plugin/views/style/Table.php
Returns the rendered value for a new (raw) value of a table cell.
Table::setCell in src/Plugin/views/style/Table.php
Render and set a raw value on the table cell in specified column and row.
Table::setTotalsRow in src/Plugin/views/style/Table.php
Write the aggregated results back into the View results totals (footer).

File

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

Class

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

Namespace

Drupal\views_aggregator\Plugin\views\style

Code

protected function renderNewWebformValue($field_handler, $row_num, array $new_values, $separator) {
  $result_row = isset($row_num) ? $field_handler->view->result[$row_num] : reset($field_handler->view->result);
  $nid = $field_handler->options['id'];
  if (isset($field_handler->options['entity_field'])) {
    $nid = $field_handler->options['entity_field'];
  }
  else {
    $nid = $field_handler->options['id'];
  }
  $cid = $field_handler->definition['webform_submission_field'];
  $data = $result_row->_entity
    ->getData();
  $rendered_values = [];
  $new_values = is_array($new_values) ? $new_values : [
    $new_values,
  ];
  foreach ($new_values as $new_value) {
    if (is_array($data[$cid])) {
      $data[$cid] = [
        $new_value,
      ];
    }
    else {
      $data[$cid] = $new_value;
    }
    $result_row->_entity
      ->setData($data);
    $rendered = $field_handler
      ->render($result_row);
    if (is_object($rendered[$cid]['#value'])) {
      $rendered_values[] = empty($rendered) ? $new_value : $rendered[$cid]['#value']
        ->__toString();
    }
    elseif (isset($rendered[$cid]['#value']['#plain_text'])) {
      $rendered_values[] = empty($rendered) ? $new_value : $rendered[$cid]['#value']['#plain_text'];
    }
    elseif (isset($rendered[$cid]['#value']['#items'])) {
      if (is_array($rendered[$cid]['#value']['#items'][0])) {
        $rendered_values[] = empty($rendered) ? $new_value : $rendered[$cid]['#value']['#items'][0]['#plain_text'];
      }
      else {
        $rendered_values[] = empty($rendered) ? $new_value : $rendered[$cid]['#value']['#items'][0]
          ->__toString();
      }
    }
    else {
      $rendered_values[] = empty($rendered) ? $new_value : $rendered[$cid]['#value'];
    }
  }
  $rendered_value = implode(empty($separator) ? ' - ' : $separator, $rendered_values);
  return is_array($rendered_value) ? $this
    ->getRenderer()
    ->renderPlain($rendered_value) : $rendered_value;
}