You are here

protected function Table::renderFromRaw in Views Aggregator Plus 8

Render a standard views field from a raw value.

The field will be rendered with appropriate CSS classes, without label.

Parameters

object $field_handler: The views_handler_field_field object belonging to the View result field.

int $row_num: The view result row number to change. Pass NULL to simply render $raw_value outside the context of a View, without affecting any rows.

mixed $raw_value: Compound or simple value. If NULL the row value of the field is re-rendered using its current (raw) value.

Return value

string The rendered value or FALSE, if the type of field is not supported.

1 call to Table::renderFromRaw()
Table::renderNewValue in src/Plugin/views/style/Table.php
Returns the rendered value for a new (raw) value of a table cell.

File

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

Class

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

Namespace

Drupal\views_aggregator\Plugin\views\style

Code

protected function renderFromRaw($field_handler, $row_num = NULL, $raw_value = NULL) {
  if (isset($field_handler->options['entity_field'])) {
    $field_name = $field_handler->options['entity_field'];
  }
  elseif (isset($field_handler->options['field'])) {
    $field_name = $field_handler->options['field'];
  }
  else {
    $field_name = $field_handler->options['id'];
  }
  if (isset($row_num)) {
    $row = $field_handler->view->result[$row_num];
  }
  else {

    // Get the first non-empty result row.
    foreach ($field_handler->view->result as $row_id => $row_value) {
      if (isset($row_value->_entity->{$field_name})) {
        $row = $row_value;
        break;
      }
      elseif (count(array_keys($row_value->_relationship_entities)) > 0) {
        foreach ($row_value->_relationship_entities as $key => $rel) {
          if (isset($row_value->_relationship_entities[$key]->{$field_name})) {
            $row = $row_value;
            break;
          }
        }
      }
    }
  }
  $display = [
    'type' => $field_handler->options['type'],
    'settings' => $field_handler->options['settings'],
    'label' => 'hidden',
  ];

  // Check, if the field is in _entity (base table).
  if (isset($row->_entity->{$field_name})) {
    $field = $row->_entity->{$field_name};
  }
  elseif (isset($row->_relationship_entities)) {
    $relationship_entity = array_keys($row->_relationship_entities);
    foreach ($relationship_entity as $key => $rel) {
      if (isset($row->_relationship_entities[$rel]->{$field_name})) {
        $field = $row->_relationship_entities[$rel]->{$field_name};
      }
    }
  }
  else {
    return 'Not found: ' . $field_name . ' > ' . $raw_value;
  }

  // Commerce fields with currency format (e.g. price)
  // store value in "number".
  if (isset($field->currency_code)) {
    $field->number = $raw_value;
  }
  else {
    $field->value = $raw_value;
  }
  $render_array = $field
    ->view($display);
  $rendered_value = $this
    ->getRenderer()
    ->renderPlain($render_array);
  return strip_tags((string) $rendered_value);
}