You are here

abstract class PaymentStatusBase in Payment 8.2

Provides a base payment status.

Plugins extending this class should provide a configuration schema that extends plugin.plugin_configuration.payment_status.payment_base.

Hierarchy

Expanded class hierarchy of PaymentStatusBase

1 file declares its use of PaymentStatusBase
PaymentStatusBaseTest.php in tests/src/Unit/Plugin/Payment/Status/PaymentStatusBaseTest.php

File

src/Plugin/Payment/Status/PaymentStatusBase.php, line 22

Namespace

Drupal\payment\Plugin\Payment\Status
View source
abstract class PaymentStatusBase extends PluginBase implements ContainerFactoryPluginInterface, PaymentStatusInterface, PluginFormInterface, ConfigurableInterface {
  use PaymentAwareTrait;

  /**
   * The current user.
   *
   * @var \Drupal\Core\Session\AccountInterface
   */
  protected $currentUser;

  /**
   * The default datetime.
   *
   * @var \Drupal\Core\Datetime\DrupalDateTime
   */
  protected $defaultDateTime;

  /**
   * The module handler.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * The payment status plugin manager.
   *
   * @var \Drupal\payment\Plugin\Payment\Status\PaymentStatusManagerInterface
   */
  protected $paymentStatusManager;

  /**
   * Constructs a new instance.
   *
   * @param mixed[] $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param mixed[] $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface
   * @param \Drupal\payment\Plugin\Payment\Status\PaymentStatusManagerInterface $payment_status_manager
   * @param \Drupal\Core\Datetime\DrupalDateTime $default_datetime
   *   The default datetime of the new status.
   */
  public function __construct(array $configuration, $plugin_id, array $plugin_definition, ModuleHandlerInterface $module_handler, PaymentStatusManagerInterface $payment_status_manager, DrupalDateTime $default_datetime) {
    $configuration += $this
      ->defaultConfiguration();
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->defaultDateTime = $default_datetime;
    $this->moduleHandler = $module_handler;
    $this->paymentStatusManager = $payment_status_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('module_handler'), $container
      ->get('plugin.manager.payment.status'), new DrupalDateTime());
  }

  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    return [
      'created' => time(),
      'id' => 0,
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function getConfiguration() {
    return $this->configuration;
  }

  /**
   * {@inheritdoc}
   */
  public function setConfiguration(array $configuration) {
    $this->configuration = $configuration + $this
      ->defaultConfiguration();
  }

  /**
   * {@inheritdoc}
   */
  public function setCreated($created) {
    $this->configuration['created'] = $created;
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function getCreated() {
    return $this->configuration['created'];
  }

  /**
   * {@inheritdoc}
   */
  function getAncestors() {
    return $this->paymentStatusManager
      ->getAncestors($this
      ->getPluginId());
  }

  /**
   * {@inheritdoc}
   */
  public function getChildren() {
    return $this->paymentStatusManager
      ->getChildren($this
      ->getPluginId());
  }

  /**
   * {@inheritdoc}
   */
  function getDescendants() {
    return $this->paymentStatusManager
      ->getDescendants($this
      ->getPluginId());
  }

  /**
   * {@inheritdoc}
   */
  function hasAncestor($plugin_id) {
    return $this->paymentStatusManager
      ->hasAncestor($this
      ->getPluginId(), $plugin_id);
  }

  /**
   * {@inheritdoc}
   */
  function isOrHasAncestor($plugin_id) {
    return $this->paymentStatusManager
      ->isOrHasAncestor($this
      ->getPluginId(), $plugin_id);
  }

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    if ($this->moduleHandler
      ->moduleExists('datetime')) {
      $elements['created'] = [
        '#default_value' => $this->defaultDateTime,
        '#required' => TRUE,
        '#title' => $this
          ->t('Date and time'),
        '#type' => 'datetime',
      ];
    }
    else {
      $elements['created'] = [
        '#default_value' => $this->defaultDateTime,
        '#type' => 'value',
      ];
      if ($this->currentUser
        ->hasPermission('administer modules')) {
        $elements['created_message'] = [
          '#type' => 'markup',
          '#markup' => $this
            ->t('Enable the <a href="@url">Datetime</a> module to set the date and time of the new payment status.', [
            '@url' => new Url('system.modules_list', [], [
              'fragment' => 'module-datetime',
            ]),
          ]),
        ];
      }
    }
    return $elements;
  }

  /**
   * {@inheritdoc}
   */
  public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
  }

  /**
   * {@inheritdoc}
   */
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PaymentAwareTrait::$payment protected property The payment.
PaymentAwareTrait::getPayment public function
PaymentAwareTrait::setPayment public function
PaymentStatusBase::$currentUser protected property The current user.
PaymentStatusBase::$defaultDateTime protected property The default datetime.
PaymentStatusBase::$moduleHandler protected property The module handler.
PaymentStatusBase::$paymentStatusManager protected property The payment status plugin manager.
PaymentStatusBase::buildConfigurationForm public function Form constructor. Overrides PluginFormInterface::buildConfigurationForm
PaymentStatusBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
PaymentStatusBase::defaultConfiguration public function Gets default configuration for this plugin. Overrides ConfigurableInterface::defaultConfiguration
PaymentStatusBase::getAncestors function Gets this payment status's ancestors. Overrides PaymentStatusInterface::getAncestors
PaymentStatusBase::getChildren public function Gets this payment status's children. Overrides PaymentStatusInterface::getChildren
PaymentStatusBase::getConfiguration public function Gets this plugin's configuration. Overrides ConfigurableInterface::getConfiguration
PaymentStatusBase::getCreated public function Gets the created date and time. Overrides PaymentStatusInterface::getCreated
PaymentStatusBase::getDescendants function Get this payment status's descendants. Overrides PaymentStatusInterface::getDescendants
PaymentStatusBase::hasAncestor function Checks if the status has a given other status as one of its ancestors. . Overrides PaymentStatusInterface::hasAncestor
PaymentStatusBase::isOrHasAncestor function Checks if the status is equal to a given other status or has it one of its ancestors. Overrides PaymentStatusInterface::isOrHasAncestor
PaymentStatusBase::setConfiguration public function Sets the configuration for this plugin instance. Overrides ConfigurableInterface::setConfiguration
PaymentStatusBase::setCreated public function Sets the created date and time. Overrides PaymentStatusInterface::setCreated
PaymentStatusBase::submitConfigurationForm public function Form submission handler. Overrides PluginFormInterface::submitConfigurationForm
PaymentStatusBase::validateConfigurationForm public function Form validation handler. Overrides PluginFormInterface::validateConfigurationForm
PaymentStatusBase::__construct public function Constructs a new instance. Overrides PluginBase::__construct
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
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.