PaymentMethodController.php in Ubercart 8.4
File
payment/uc_payment/src/Controller/PaymentMethodController.php
View source
<?php
namespace Drupal\uc_payment\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\uc_payment\PaymentMethodInterface;
class PaymentMethodController extends ControllerBase {
public function addForm($plugin_id) {
$entity = $this
->entityTypeManager()
->getStorage('uc_payment_method')
->create([
'plugin' => $plugin_id,
]);
return $this
->entityFormBuilder()
->getForm($entity);
}
public function performOperation(PaymentMethodInterface $uc_payment_method, $op) {
$uc_payment_method
->{$op}()
->save();
if ($op == 'enable') {
$this
->messenger()
->addMessage($this
->t('The %label payment method has been enabled.', [
'%label' => $uc_payment_method
->label(),
]));
}
elseif ($op == 'disable') {
$this
->messenger()
->addMessage($this
->t('The %label payment method has been disabled.', [
'%label' => $uc_payment_method
->label(),
]));
}
$url = $uc_payment_method
->toUrl('collection');
return $this
->redirect($url
->getRouteName(), $url
->getRouteParameters(), $url
->getOptions());
}
}