class SetStatus in Payment 8.2
Sets a status on a payment.
Plugin annotation
@Action(
id = "payment_set_status",
label = @Translation("Set payment status"),
type = "payment"
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\Core\Action\ActionBase implements ActionInterface
- class \Drupal\Core\Action\ConfigurableActionBase implements ConfigurableInterface, ConfigurablePluginInterface, DependentPluginInterface, PluginFormInterface
- class \Drupal\payment\Plugin\Action\SetStatus implements ContainerFactoryPluginInterface
- class \Drupal\Core\Action\ConfigurableActionBase implements ConfigurableInterface, ConfigurablePluginInterface, DependentPluginInterface, PluginFormInterface
- class \Drupal\Core\Action\ActionBase implements ActionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of SetStatus
1 file declares its use of SetStatus
- SetStatusTest.php in tests/
src/ Unit/ Plugin/ Action/ SetStatusTest.php
File
- src/
Plugin/ Action/ SetStatus.php, line 25
Namespace
Drupal\payment\Plugin\ActionView source
class SetStatus extends ConfigurableActionBase implements ContainerFactoryPluginInterface {
/**
* The payment status type.
*
* @var \Drupal\plugin\PluginType\PluginTypeInterface
*/
protected $paymentStatusType;
/**
* The plugin selector manager.
*
* @var \Drupal\plugin\Plugin\Plugin\PluginSelector\PluginSelectorManagerInterface
*/
protected $pluginSelectorManager;
/**
* 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\StringTranslation\TranslationInterface $string_translation
* The string translator.
* @param \Drupal\plugin\Plugin\Plugin\PluginSelector\PluginSelectorManagerInterface $plugin_selector_manager
* The plugin selector manager.
* @param \Drupal\plugin\PluginType\PluginTypeInterface $payment_status_type
* The payment status type.
*/
public function __construct(array $configuration, $plugin_id, array $plugin_definition, TranslationInterface $string_translation, PluginSelectorManagerInterface $plugin_selector_manager, PluginTypeInterface $payment_status_type) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->pluginSelectorManager = $plugin_selector_manager;
$this->paymentStatusType = $payment_status_type;
$this->stringTranslation = $string_translation;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
/** @var \Drupal\plugin\PluginType\PluginTypeManagerInterface $plugin_type_manager */
$plugin_type_manager = $container
->get('plugin.plugin_type_manager');
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('string_translation'), $container
->get('plugin.manager.plugin.plugin_selector'), $plugin_type_manager
->getPluginType('payment_status'));
}
/**
* {@inheritdoc}
*/
public function execute(PaymentInterface $payment = NULL) {
if ($payment) {
$status = $this->paymentStatusType
->getPluginManager()
->createInstance($this->configuration['payment_status_plugin_id']);
$payment
->setPaymentStatus($status);
}
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return array(
'payment_status_plugin_id' => '',
);
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form['payment_status_plugin_id'] = $this
->getPluginSelector($form_state)
->buildSelectorForm([], $form_state);
return $form;
}
/**
* {@inheritdoc}
*/
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
$this
->getPluginSelector($form_state)
->validateSelectorForm($form['payment_status_plugin_id'], $form_state);
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$this
->getPluginSelector($form_state)
->submitSelectorForm($form['payment_status_plugin_id'], $form_state);
$this->configuration['payment_status_plugin_id'] = $this
->getPluginSelector($form_state)
->getSelectedPlugin()
->getPluginId();
}
/**
* {@inheritdoc}
*/
public function access($payment, AccountInterface $account = NULL, $return_as_object = FALSE) {
if ($payment instanceof PaymentInterface) {
return $payment
->access('update', $account, $return_as_object);
}
$access = AccessResult::forbidden();
return $return_as_object ? $access : $access
->isAllowed();
}
/**
* Gets the plugin selector.
*
* @param \Drupal\Core\Form\FormStateInterface $form_state
*
* @return \Drupal\plugin\Plugin\Plugin\PluginSelector\PluginSelectorInterface
*/
protected function getPluginSelector(FormStateInterface $form_state) {
if (!$form_state
->has('plugin_selector')) {
$plugin_selector = $this->pluginSelectorManager
->createInstance('payment_select_list');
$plugin_selector
->setSelectablePluginType($this->paymentStatusType);
$plugin_selector
->setRequired();
$plugin_selector
->setLabel($this
->t('Payment status'));
$plugin_selector
->setCollectPluginConfiguration(FALSE);
$form_state
->set('plugin_selector', $plugin_selector);
}
return $form_state
->get('plugin_selector');
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ActionBase:: |
public | function |
Executes the plugin for an array of objects. Overrides ActionInterface:: |
3 |
ConfigurableActionBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
1 |
ConfigurableActionBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
ConfigurableActionBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
SetStatus:: |
protected | property | The payment status type. | |
SetStatus:: |
protected | property | The plugin selector manager. | |
SetStatus:: |
public | function |
Checks object access. Overrides ActionInterface:: |
|
SetStatus:: |
public | function |
Form constructor. Overrides PluginFormInterface:: |
|
SetStatus:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
SetStatus:: |
public | function |
Gets default configuration for this plugin. Overrides ConfigurableActionBase:: |
|
SetStatus:: |
public | function |
Executes the plugin. Overrides ExecutableInterface:: |
|
SetStatus:: |
protected | function | Gets the plugin selector. | |
SetStatus:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
|
SetStatus:: |
public | function |
Form validation handler. Overrides ConfigurableActionBase:: |
|
SetStatus:: |
public | function |
Constructs a new instance. Overrides ConfigurableActionBase:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |