You are here

public function ReportDateField::getItems in Commerce Reporting 8

Gets an array of items for the field.

Parameters

\Drupal\views\ResultRow $values: The result row object containing the values.

Return value

array An array of items for the field.

Overrides EntityField::getItems

File

src/Plugin/views/field/ReportDateField.php, line 167

Class

ReportDateField
Plugin annotation @ViewsField("commerce_reports_report_date_field");

Namespace

Drupal\commerce_reports\Plugin\views\field

Code

public function getItems(ResultRow $values) {
  if (!$this->displayHandler
    ->useGroupBy()) {
    $build_list = $this
      ->getEntityFieldRenderer()
      ->render($values, $this);
  }
  else {

    // Render date values from SQL result.
    $alias = $this->aliases[$this->definition['field_name']];
    return [
      [
        'rendered' => $values->{$alias},
      ],
    ];
  }

  // Code from parent function.
  if (!$build_list) {
    return [];
  }
  if ($this->options['field_api_classes']) {
    return [
      [
        'rendered' => $this->renderer
          ->render($build_list),
      ],
    ];
  }

  // Render using the formatted data itself.
  $items = [];

  // Each item is extracted and rendered separately, the top-level formatter
  // render array itself is never rendered, so we extract its bubbleable
  // metadata and add it to each child individually.
  $bubbleable = BubbleableMetadata::createFromRenderArray($build_list);
  foreach (Element::children($build_list) as $delta) {
    BubbleableMetadata::createFromRenderArray($build_list[$delta])
      ->merge($bubbleable)
      ->applyTo($build_list[$delta]);
    $items[$delta] = [
      'rendered' => $build_list[$delta],
      // Add the raw field items (for use in tokens).
      'raw' => $build_list['#items'][$delta],
    ];
  }
  return $items;
}