ListPaymentMethods.php in Payment 8.2
File
src/Controller/ListPaymentMethods.php
View source
<?php
namespace Drupal\payment\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\payment\Plugin\Payment\Method\PaymentMethodManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ListPaymentMethods extends ControllerBase {
protected $paymentMethodManager;
public function __construct(TranslationInterface $string_translation, PaymentMethodManagerInterface $payment_method_manager) {
$this->paymentMethodManager = $payment_method_manager;
$this->stringTranslation = $string_translation;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('string_translation'), $container
->get('plugin.manager.payment.method'));
}
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;
}
}