You are here

protected function InvoiceController::addInvoiceInfo in Commerce Invoice 7.2

Add a table of invoice information to the content render array.

Parameters

Invoice $invoice:

array &$content:

1 call to InvoiceController::addInvoiceInfo()
InvoiceController::buildContent in src/Entity/InvoiceController.php

File

src/Entity/InvoiceController.php, line 95
The entity controller for invoices.

Class

InvoiceController

Namespace

Drupal\commerce_invoice\Entity

Code

protected function addInvoiceInfo(Invoice $invoice, array &$content) {
  $info = [];
  $info[t('Invoice ID')] = check_plain($invoice->invoice_id);
  $info[t('Owner')] = [
    '#theme' => 'username',
    '#account' => $invoice
      ->wrapper()->owner
      ->value(),
  ];
  $info[t('Invoice number')] = $invoice
    ->hasInvoiceNumber() ? check_plain($invoice
    ->getInvoiceNumber()
    ->__toString()) : t('Not yet generated');
  $info[t('Invoice date')] = check_plain(format_date($invoice->invoice_date));
  if ($invoice->invoice_due) {
    $info[t('Due date')] = check_plain(format_date($invoice->invoice_due));
  }
  $info[t('Status')] = commerce_invoice_statuses()[$invoice->invoice_status];
  $info[t('Order')] = isset($invoice->order_id) ? l($invoice
    ->wrapper()->order->order_number
    ->value(), 'admin/commerce/orders/' . $invoice->order_id) : t('None');
  $info[t('Order revision')] = isset($invoice->order_revision_id) ? check_plain($invoice->order_revision_id) : t('None');
  $pattern = $invoice
    ->getNumberPattern();
  $info[t('Invoice number pattern')] = format_string('@label: <code>@pattern</code>', [
    '@label' => $pattern->label,
    '@pattern' => $pattern->pattern,
  ]);
  $info[t('Created')] = check_plain(format_date($invoice->created));
  $info[t('Last modified')] = check_plain(format_date($invoice->changed));
  if (!empty($info)) {
    $content['info'] = [
      '#theme' => 'table',
      '#rows' => [],
    ];
    foreach ($info as $label => $value) {
      $content['info']['#rows'][] = [
        [
          'data' => $label,
          'header' => TRUE,
        ],
        is_array($value) ? [
          'data' => $value,
        ] : $value,
      ];
    }
  }
}