PaymentMethodConfigurationOperationsProvider.php in Payment 8.2
File
src/Plugin/Payment/Method/PaymentMethodConfigurationOperationsProvider.php
View source
<?php
namespace Drupal\payment\Plugin\Payment\Method;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\EntityListBuilderInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Routing\RedirectDestinationInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\plugin\PluginOperationsProviderInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
abstract class PaymentMethodConfigurationOperationsProvider implements PluginOperationsProviderInterface, ContainerInjectionInterface {
use StringTranslationTrait;
protected $paymentMethodConfigurationListBuilder;
protected $paymentMethodConfigurationStorage;
protected $redirectDestination;
public function __construct(TranslationInterface $string_translation, RedirectDestinationInterface $redirect_destination, EntityStorageInterface $payment_method_configuration_storage, EntityListBuilderInterface $payment_method_configuration_list_builder) {
$this->paymentMethodConfigurationListBuilder = $payment_method_configuration_list_builder;
$this->paymentMethodConfigurationStorage = $payment_method_configuration_storage;
$this->redirectDestination = $redirect_destination;
$this->stringTranslation = $string_translation;
}
public static function create(ContainerInterface $container) {
$entity_type_manager = $container
->get('entity_type.manager');
return new static($container
->get('string_translation'), $container
->get('redirect.destination'), $entity_type_manager
->getStorage('payment_method_configuration'), $entity_type_manager
->getListBuilder('payment_method_configuration'));
}
protected abstract function getPaymentMethodConfiguration($plugin_id);
public function getOperations($plugin_id) {
$payment_method_configuration_operations = $this->paymentMethodConfigurationListBuilder
->getOperations($this
->getPaymentMethodConfiguration($plugin_id));
$titles = array(
'edit' => $this
->t('Edit configuration'),
'delete' => $this
->t('Delete configuration'),
'enable' => $this
->t('Enable configuration'),
'disable' => $this
->t('Disable configuration'),
);
$operations = [];
foreach ($payment_method_configuration_operations as $name => $payment_method_configuration_operation) {
if (array_key_exists($name, $titles)) {
$operations[$name] = $payment_method_configuration_operation;
$operations[$name]['title'] = $titles[$name];
$operations[$name]['query']['destination'] = $this->redirectDestination
->get();
}
}
return $operations;
}
}