You are here

public function InvoiceTotalSummary::viewElements in Commerce Invoice 8.2

Builds a renderable array for a field value.

Parameters

\Drupal\Core\Field\FieldItemListInterface $items: The field values to be rendered.

string $langcode: The language that should be used to render the field.

Return value

array A renderable array for $items, as an array of child elements keyed by consecutive numeric indexes starting from 0.

Overrides FormatterInterface::viewElements

File

src/Plugin/Field/FieldFormatter/InvoiceTotalSummary.php, line 77

Class

InvoiceTotalSummary
Plugin implementation of the 'commerce_invoice_total_summary' formatter.

Namespace

Drupal\commerce_invoice\Plugin\Field\FieldFormatter

Code

public function viewElements(FieldItemListInterface $items, $langcode) {

  /** @var \Drupal\commerce_invoice\Entity\InvoiceInterface $invoice */
  $invoice = $items
    ->getEntity();
  $elements = [];
  if (!$items
    ->isEmpty()) {
    $elements[0] = [
      '#theme' => 'commerce_invoice_total_summary',
      '#invoice_entity' => $invoice,
      '#totals' => $this->invoiceTotalSummary
        ->buildTotals($invoice),
    ];
  }
  return $elements;
}