You are here

protected function PaymentListBuilder::getDefaultOperations in Commerce Core 8.2

Gets this list's default operations.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity the operations are for.

Return value

array The array structure is identical to the return value of self::getOperations().

Overrides EntityListBuilder::getDefaultOperations

File

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

Class

PaymentListBuilder
Defines the list builder for payments.

Namespace

Drupal\commerce_payment

Code

protected function getDefaultOperations(EntityInterface $entity) {
  $operations = [];

  /** @var \Drupal\commerce_payment\Entity\PaymentInterface $entity */
  $payment_gateway = $entity
    ->getPaymentGateway();

  // Add the gateway-specific operations.
  if ($payment_gateway) {
    $operations = $payment_gateway
      ->getPlugin()
      ->buildPaymentOperations($entity);

    // Filter out operations that aren't allowed.
    $operations = array_filter($operations, function ($operation) {
      return !empty($operation['access']);
    });

    // Build the url for each operation.
    $base_route_parameters = [
      'commerce_payment' => $entity
        ->id(),
      'commerce_order' => $entity
        ->getOrderId(),
    ];
    foreach ($operations as $operation_id => $operation) {
      $route_parameters = $base_route_parameters + [
        'operation' => $operation_id,
      ];
      $operation['url'] = new Url('entity.commerce_payment.operation_form', $route_parameters);
      $operations[$operation_id] = $operation;
    }
  }

  // Add the non-gateway-specific operations.
  if ($entity
    ->access('delete')) {
    $operations['delete'] = [
      'title' => $this
        ->t('Delete'),
      'weight' => 100,
      'url' => $entity
        ->toUrl('delete-form'),
    ];
  }
  return $operations;
}