You are here

abstract class PaymentMethodConfigurationOperationsProvider in Payment 8.2

Provides operations for payment methods based on config entities.

Hierarchy

Expanded class hierarchy of PaymentMethodConfigurationOperationsProvider

1 file declares its use of PaymentMethodConfigurationOperationsProvider
PaymentMethodConfigurationOperationsProviderTest.php in tests/src/Unit/Plugin/Payment/Method/PaymentMethodConfigurationOperationsProviderTest.php

File

src/Plugin/Payment/Method/PaymentMethodConfigurationOperationsProvider.php, line 21

Namespace

Drupal\payment\Plugin\Payment\Method
View source
abstract class PaymentMethodConfigurationOperationsProvider implements PluginOperationsProviderInterface, ContainerInjectionInterface {
  use StringTranslationTrait;

  /**
   * The payment method configuration list builder.
   *
   * @var \Drupal\Core\Entity\EntityListBuilderInterface
   */
  protected $paymentMethodConfigurationListBuilder;

  /**
   * The payment method configuration storage.
   *
   * @var \Drupal\Core\Entity\EntityStorageInterface
   */
  protected $paymentMethodConfigurationStorage;

  /**
   * The redirect destination.
   *
   * @var \Drupal\Core\Routing\RedirectDestinationInterface
   */
  protected $redirectDestination;

  /**
   * Constructs a new instance.
   *
   * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
   *   The string translator.
   * @param \Drupal\Core\Routing\RedirectDestinationInterface $redirect_destination
   *   The redirect destination.
   * @param \Drupal\Core\Entity\EntityStorageInterface $payment_method_configuration_storage
   *   The payment method configuration storage.
   * @param \Drupal\Core\Entity\EntityListBuilderInterface $payment_method_configuration_list_builder
   *   The payment method configuration list builder.
   */
  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;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {

    /** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */
    $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'));
  }

  /**
   * Gets the payment method configuration entity for this plugin.
   *
   * @param string $plugin_id
   *   This plugin's ID.
   *
   * @return \Drupal\payment\Entity\PaymentMethodConfigurationInterface
   */
  protected abstract function getPaymentMethodConfiguration($plugin_id);

  /**
   * {@inheritdoc}
   */
  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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PaymentMethodConfigurationOperationsProvider::$paymentMethodConfigurationListBuilder protected property The payment method configuration list builder.
PaymentMethodConfigurationOperationsProvider::$paymentMethodConfigurationStorage protected property The payment method configuration storage.
PaymentMethodConfigurationOperationsProvider::$redirectDestination protected property The redirect destination.
PaymentMethodConfigurationOperationsProvider::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
PaymentMethodConfigurationOperationsProvider::getOperations public function Gets plugin operations. Overrides PluginOperationsProviderInterface::getOperations
PaymentMethodConfigurationOperationsProvider::getPaymentMethodConfiguration abstract protected function Gets the payment method configuration entity for this plugin. 1
PaymentMethodConfigurationOperationsProvider::__construct public function Constructs a new instance.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.