AddPaymentMethodConfiguration.php in Payment 8.2
File
src/Controller/AddPaymentMethodConfiguration.php
View source
<?php
namespace Drupal\payment\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Entity\EntityFormBuilderInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\payment\Plugin\Payment\MethodConfiguration\PaymentMethodConfigurationManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
class AddPaymentMethodConfiguration extends ControllerBase {
protected $paymentMethodConfigurationManager;
protected $requestStack;
public function __construct(RequestStack $request_stack, TranslationInterface $string_translation, EntityTypeManagerInterface $entity_type_manager, PaymentMethodConfigurationManagerInterface $payment_method_configuration_manager, EntityFormBuilderInterface $entity_form_builder, AccountInterface $current_user) {
$this->currentUser = $current_user;
$this->entityTypeManager = $entity_type_manager;
$this->entityFormBuilder = $entity_form_builder;
$this->paymentMethodConfigurationManager = $payment_method_configuration_manager;
$this->requestStack = $request_stack;
$this->stringTranslation = $string_translation;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('request_stack'), $container
->get('string_translation'), $container
->get('entity_type.manager'), $container
->get('plugin.manager.payment.method_configuration'), $container
->get('entity.form_builder'), $container
->get('current_user'));
}
public function execute($plugin_id) {
$payment_method_configuration = $this->entityTypeManager
->getStorage('payment_method_configuration')
->create([
'pluginId' => $plugin_id,
]);
return $this->entityFormBuilder
->getForm($payment_method_configuration, 'default');
}
public function title($plugin_id) {
$plugin_definition = $this->paymentMethodConfigurationManager
->getDefinition($plugin_id);
return $this
->t('Add %label payment method configuration', [
'%label' => $plugin_definition['label'],
]);
}
public function access() {
$plugin_id = $this->requestStack
->getCurrentRequest()->attributes
->get('plugin_id');
return $this->entityTypeManager
->getAccessControlHandler('payment_method_configuration')
->createAccess($plugin_id, $this->currentUser, [], TRUE);
}
}