You are here

public function ListPaymentTypes::execute in Payment 8.2

Displays a list of available payment types.

Return value

array A render array.

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

File

src/Controller/ListPaymentTypes.php, line 56

Class

ListPaymentTypes
Handles the "list payment types" route.

Namespace

Drupal\payment\Controller

Code

public function execute() {
  $table = [
    '#empty' => $this
      ->t('There are no available payment types.'),
    '#header' => [
      $this
        ->t('Type'),
      $this
        ->t('Description'),
      $this
        ->t('Operations'),
    ],
    '#type' => 'table',
  ];
  $definitions = $this->paymentTypeManager
    ->getDefinitions();
  unset($definitions['payment_unavailable']);
  foreach ($definitions as $plugin_id => $definition) {
    $operations_provider = $this->paymentTypeManager
      ->getOperationsProvider($plugin_id);
    $operations = $operations_provider ? $operations_provider
      ->getOperations($plugin_id) : [];

    // Add the payment type's global configuration operation.
    $operations['configure'] = [
      'url' => new Url('payment.payment_type', [
        'bundle' => $plugin_id,
      ]),
      'title' => $this
        ->t('Configure'),
    ];

    // Add Field UI operations.
    if ($this->moduleHandler
      ->moduleExists('field_ui')) {
      if ($this->currentUser
        ->hasPermission('administer payment fields')) {
        $operations['manage-fields'] = [
          'title' => $this
            ->t('Manage fields'),
          'url' => new Url('entity.payment.field_ui_fields', [
            'bundle' => $plugin_id,
          ]),
        ];
      }
      if ($this->currentUser
        ->hasPermission('administer payment form display')) {
        $operations['manage-form-display'] = [
          'title' => $this
            ->t('Manage form display'),
          'url' => new Url('entity.entity_form_display.payment.default', [
            'bundle' => $plugin_id,
          ]),
        ];
      }
      if ($this->currentUser
        ->hasPermission('administer payment display')) {
        $operations['manage-display'] = [
          'title' => $this
            ->t('Manage display'),
          'url' => new Url('entity.entity_view_display.payment.default', [
            'bundle' => $plugin_id,
          ]),
        ];
      }
    }
    $table[$plugin_id]['label'] = [
      '#markup' => $definition['label'],
    ];
    $table[$plugin_id]['description'] = [
      '#markup' => isset($definition['description']) ? $definition['description'] : NULL,
    ];
    $table[$plugin_id]['operations'] = [
      '#links' => $operations,
      '#type' => 'operations',
    ];
  }
  return $table;
}