You are here

public function ListPaymentMethods::execute in Payment 8.2

Lists all available payment method plugins.

Return value

array A renderable array.

1 string reference to 'ListPaymentMethods::execute'
payment.routing.yml in ./payment.routing.yml
payment.routing.yml

File

src/Controller/ListPaymentMethods.php, line 46

Class

ListPaymentMethods
Handles the "list all payment methods" route.

Namespace

Drupal\payment\Controller

Code

public function execute() {
  $rows = [];
  foreach ($this->paymentMethodManager
    ->getDefinitions() as $plugin_id => $definition) {
    $operations_provider = $this->paymentMethodManager
      ->getOperationsProvider($plugin_id);
    $row = [
      'label' => [
        '#markup' => $definition['label'],
      ],
      'status' => [
        '#markup' => $definition['active'] ? $this
          ->t('Enabled') : $this
          ->t('Disabled'),
      ],
      'operations' => [
        '#type' => 'operations',
        '#links' => $operations_provider ? $operations_provider
          ->getOperations($plugin_id) : [],
      ],
    ];
    if (!$definition['active']) {
      $row['#attributes']['class'] = [
        'payment-method-disabled',
      ];
    }
    $rows[$plugin_id] = $row;
  }
  return [
    '#attached' => [
      'library' => [
        'payment/payment_method.list',
      ],
    ],
    '#attributes' => [
      'class' => [
        'payment-method-list',
      ],
    ],
    '#header' => [
      $this
        ->t('Name'),
      $this
        ->t('Status'),
      $this
        ->t('Operations'),
    ],
    '#type' => 'table',
  ] + $rows;
}