abstract class PaymentMethodConfigurationBase in Payment 8.2
Provides a base payment method configuration plugin.
Plugins extending this class should provide a configuration schema that extends plugin.plugin_configuration.payment_method_configuration.payment_base.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\payment\Plugin\Payment\MethodConfiguration\PaymentMethodConfigurationBase implements ConfigurableInterface, DependentPluginInterface, PaymentMethodConfigurationInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of PaymentMethodConfigurationBase
1 file declares its use of PaymentMethodConfigurationBase
- PaymentMethodConfigurationBaseTest.php in tests/
src/ Unit/ Plugin/ Payment/ MethodConfiguration/ PaymentMethodConfigurationBaseTest.php
File
- src/
Plugin/ Payment/ MethodConfiguration/ PaymentMethodConfigurationBase.php, line 25
Namespace
Drupal\payment\Plugin\Payment\MethodConfigurationView source
abstract class PaymentMethodConfigurationBase extends PluginBase implements PaymentMethodConfigurationInterface, ConfigurableInterface, DependentPluginInterface {
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* Constructs a new instance.
*
* @param mixed[] $configuration
* @param string $plugin_id
* @param mixed[] $plugin_definition
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
* The string translator.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
*/
public function __construct(array $configuration, $plugin_id, array $plugin_definition, TranslationInterface $string_translation, ModuleHandlerInterface $module_handler) {
$configuration += $this
->defaultConfiguration();
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->moduleHandler = $module_handler;
$this->stringTranslation = $string_translation;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('string_translation'), $container
->get('module_handler'));
}
/**
* {@inheritdoc}
*/
public function calculateDependencies() {
return [];
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return array(
'message_text' => '',
'message_text_format' => 'plain_text',
);
}
/**
* {@inheritdoc}
*/
public function getConfiguration() {
return $this->configuration;
}
/**
* {@inheritdoc}
*/
public function setConfiguration(array $configuration) {
$this->configuration = $configuration + $this
->defaultConfiguration();
}
/**
* Sets payer message text.
*
* @param string $text
*
* @return \Drupal\payment\Plugin\Payment\Method\PaymentMethodInterface
*/
public function setMessageText($text) {
$this->configuration['message_text'] = $text;
return $this;
}
/**
* Gets the payer message text.
*
* @return string
*/
public function getMessageText() {
return $this->configuration['message_text'];
}
/**
* Sets payer message text format.
*
* @param string $format
* The machine name of the text format the payer message is in.
*
* @return \Drupal\payment\Plugin\Payment\Method\PaymentMethodInterface
*/
public function setMessageTextFormat($format) {
$this->configuration['message_text_format'] = $format;
return $this;
}
/**
* Gets the payer message text format.
*
* @return string
*/
public function getMessageTextFormat() {
return $this->configuration['message_text_format'];
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
// @todo Add a token overview, possibly when Token.module has been ported.
$elements['message'] = array(
'#tree' => TRUE,
'#type' => 'textarea',
'#title' => $this
->t('Payment form message'),
'#default_value' => $this
->getMessageText(),
);
if ($this->moduleHandler
->moduleExists('filter')) {
$elements['message']['#type'] = 'text_format';
$elements['message']['#format'] = $this
->getMessageTextFormat();
}
return $elements;
}
/**
* {@inheritdoc}
*/
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValues();
$message = NestedArray::getValue($values, $form['message']['#parents']);
if ($this->moduleHandler
->moduleExists('filter')) {
$this
->setMessageText($message['value']);
$this
->setMessageTextFormat($message['format']);
}
else {
$this
->setMessageText($message);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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. | |
PaymentMethodConfigurationBase:: |
protected | property | The module handler. | |
PaymentMethodConfigurationBase:: |
public | function |
Form constructor. Overrides PluginFormInterface:: |
1 |
PaymentMethodConfigurationBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
|
PaymentMethodConfigurationBase:: |
public static | function | 1 | |
PaymentMethodConfigurationBase:: |
public | function |
Gets default configuration for this plugin. Overrides ConfigurableInterface:: |
1 |
PaymentMethodConfigurationBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
PaymentMethodConfigurationBase:: |
public | function | Gets the payer message text. | |
PaymentMethodConfigurationBase:: |
public | function | Gets the payer message text format. | |
PaymentMethodConfigurationBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
PaymentMethodConfigurationBase:: |
public | function | Sets payer message text. | |
PaymentMethodConfigurationBase:: |
public | function | Sets payer message text format. | |
PaymentMethodConfigurationBase:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
1 |
PaymentMethodConfigurationBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
1 |
PaymentMethodConfigurationBase:: |
public | function |
Constructs a new instance. Overrides PluginBase:: |
1 |
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. | |
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. |