You are here

private function Table::getCellRaw in Views Aggregator Plus 8

Returns the raw, unrendered result at the intersection of column and row.

Should normally not be called, especially not for "Global: Custom text" fields.

Parameters

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

object $result_row: The result row.

bool $compressed: If the result is a (nested) array, return the first primitive value.

Return value

string the raw contents of the cell

1 call to Table::getCellRaw()
Table::getCell in src/Plugin/views/style/Table.php
Returns the raw or rendered result at the intersection of column and row.

File

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

Class

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

Namespace

Drupal\views_aggregator\Plugin\views\style

Code

private function getCellRaw($field_handler, $result_row, $compressed = TRUE) {
  if (isset($field_handler->options['entity_field'])) {
    $field_name = $field_handler->options['entity_field'];
  }
  elseif ($this
    ->isWebformNumeric($field_handler) || $this
    ->isWebformField($field_handler)) {
    $field_name = $field_handler->definition['webform_submission_field'];
  }
  else {
    $field_name = $field_handler->options['id'];
  }

  // Get field from the relationship_entities, otherwise from the entity.
  if ($field_handler->options['relationship'] && $field_handler->options['relationship'] != 'none') {
    $relationship = $field_handler->options['relationship'];
    $source = $result_row->_relationship_entities[$relationship];
  }
  else {
    $source = $result_row->_entity;
  }
  if (isset($source->{$field_name})) {
    $field = $source->{$field_name};
  }

  // "Commerce" fields - prepare totals of multiple currencies.
  if ($this
    ->isCommerceField($field_handler)) {
    $field_id = $field_handler->options['id'];
    if (isset($field->currency_code)) {
      $field_value = $field->number;

      // Write the values into an array (field, currency, value)
      if (!isset($this->commerce_field_values[$field_id])) {
        $this->commerce_field_values[$field_id] = [
          $field->currency_code => [
            $field->number,
          ],
        ];
      }
      else {
        if (isset($this->commerce_field_values[$field_id][$field->currency_code])) {
          $this->commerce_field_values[$field_id][$field->currency_code][] = $field->number;
        }
        else {
          $this->commerce_field_values[$field_id][$field->currency_code] = [
            $field->number,
          ];
        }
      }
    }
  }

  // Get the commerce number.
  if (isset($field->number)) {
    $value = $field->number;
  }
  elseif (isset($field->value)) {
    $value = $field->value;
  }
  elseif ($this
    ->isWebformField($field_handler) || $this
    ->isWebformNumeric($field_handler)) {
    if (isset($source
      ->getData()[$field_name])) {
      $value = $source
        ->getData()[$field_name];
    }
  }
  elseif (substr($field_name, 0, 10) === 'attribute_') {
    $attribute_values = $source
      ->getAttributeValue($field_name);
    $value = $attribute_values
      ->getName();
  }
  elseif (isset($field) && NULL !== $field
    ->getValue()) {
    $value = $field
      ->getValue();
  }
  elseif (NULL !== $this
    ->getFieldValue($result_row->index, $field_name)) {
    $value = $this
      ->getFieldValue($result_row->index, $field_name);
  }
  else {
    $value = '';
  }

  // Deal with multiple subvalues like Entity reference multivalue fields
  // (lists), AddressFields etc.
  // The value is an array - only count function makes sense here, e.g. sum
  // will return some weird number, summing up the first id in the list.
  if ($compressed && is_array($value)) {
    $value = reset($value);
    if (is_array($value)) {
      $value = reset($value);
    }
  }
  return $value;
}