You are here

public function PaymentListBuilder::buildRow in Commerce Core 8.2

Builds a row for an entity in the entity listing.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity for this row of the list.

Return value

array A render array structure of fields for this entity.

Overrides EntityListBuilder::buildRow

See also

\Drupal\Core\Entity\EntityListBuilder::render()

File

modules/payment/src/PaymentListBuilder.php, line 162

Class

PaymentListBuilder
Defines the list builder for payments.

Namespace

Drupal\commerce_payment

Code

public function buildRow(EntityInterface $entity) {

  /** @var \Drupal\commerce_payment\Entity\PaymentInterface $entity */
  $amount = $entity
    ->getAmount();
  $formatted_amount = $this->currencyFormatter
    ->format($amount
    ->getNumber(), $amount
    ->getCurrencyCode());
  $refunded_amount = $entity
    ->getRefundedAmount();
  if ($refunded_amount && !$refunded_amount
    ->isZero()) {
    $formatted_amount .= ' ' . $this
      ->t('Refunded:') . ' ';
    $formatted_amount .= $this->currencyFormatter
      ->format($refunded_amount
      ->getNumber(), $refunded_amount
      ->getCurrencyCode());
  }
  $payment_gateway = $entity
    ->getPaymentGateway();
  $row['label'] = $formatted_amount;
  $row['state'] = $entity
    ->getState()
    ->getLabel();
  $row['payment_gateway'] = $payment_gateway ? $payment_gateway
    ->label() : $this
    ->t('N/A');
  foreach ([
    'authorized',
    'completed',
  ] as $field) {
    if ($entity
      ->get($field)
      ->isEmpty()) {
      $row[$field] = '';
      continue;
    }
    $row[$field] = $this->dateFormatter
      ->format($entity
      ->get($field)->value, 'short');
  }

  // Add the AVS response code label beneath the gateway name if it exists.
  if ($avs_response_code = $entity
    ->getAvsResponseCode()) {
    $row['avs_response'] = $this
      ->t('AVS response: [@code] @label', [
      '@code' => $avs_response_code,
      '@label' => $entity
        ->getAvsResponseCodeLabel(),
    ]);
  }
  else {
    $row['avs_response'] = '';
  }
  $row['remote_id'] = $entity
    ->getRemoteId() ?: $this
    ->t('N/A');
  return $row + parent::buildRow($entity);
}