abstract class InlineFormBase in Commerce Core 8.2
Provides the base class for inline forms.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\commerce\Plugin\Commerce\InlineForm\InlineFormBase implements InlineFormInterface, ContainerFactoryPluginInterface uses AjaxFormTrait
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of InlineFormBase
1 file declares its use of InlineFormBase
- CouponRedemption.php in modules/
promotion/ src/ Plugin/ Commerce/ InlineForm/ CouponRedemption.php
File
- src/
Plugin/ Commerce/ InlineForm/ InlineFormBase.php, line 17
Namespace
Drupal\commerce\Plugin\Commerce\InlineFormView source
abstract class InlineFormBase extends PluginBase implements InlineFormInterface, ContainerFactoryPluginInterface {
use AjaxFormTrait;
/**
* Constructs a new InlineFormBase object.
*
* @param array $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.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this
->setConfiguration($configuration);
$this
->validateConfiguration();
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition);
}
/**
* {@inheritdoc}
*/
public function getConfiguration() {
return $this->configuration;
}
/**
* {@inheritdoc}
*/
public function setConfiguration(array $configuration) {
$this->configuration = NestedArray::mergeDeep($this
->defaultConfiguration(), $configuration);
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [];
}
/**
* Gets the required configuration for this plugin.
*
* @return string[]
* The required configuration keys.
*/
protected function requiredConfiguration() {
return [];
}
/**
* Validates configuration.
*
* @throws \RuntimeException
* Thrown if a configuration value is invalid.
*/
protected function validateConfiguration() {
foreach ($this
->requiredConfiguration() as $key) {
if (empty($this->configuration[$key])) {
throw new \RuntimeException(sprintf('The "%s" plugin requires the "%s" configuration key', $this->pluginId, $key));
}
}
}
/**
* {@inheritdoc}
*/
public function getLabel() {
return $this->pluginDefinition['label'];
}
/**
* {@inheritdoc}
*/
public function buildInlineForm(array $inline_form, FormStateInterface $form_state) {
$inline_form['#type'] = 'container';
$inline_form['#tree'] = TRUE;
// Workaround for core bug #2897377.
$inline_form['#id'] = Html::getId('edit-' . implode('-', $inline_form['#parents']));
// Automatically validate and submit inline forms.
$inline_form['#inline_form'] = $this;
$inline_form['#process'][] = [
CommerceElementTrait::class,
'attachElementSubmit',
];
$inline_form['#element_validate'][] = [
CommerceElementTrait::class,
'validateElementSubmit',
];
$inline_form['#element_validate'][] = [
get_class($this),
'runValidate',
];
$inline_form['#commerce_element_submit'][] = [
get_class($this),
'runSubmit',
];
// Allow inline forms to modify the page title.
$inline_form['#process'][] = [
get_class($this),
'updatePageTitle',
];
// Tell commerce_form_alter() to fire inline form alter hooks.
$form_state
->set('has_commerce_inline_forms', TRUE);
return $inline_form;
}
/**
* {@inheritdoc}
*/
public function validateInlineForm(array &$inline_form, FormStateInterface $form_state) {
}
/**
* {@inheritdoc}
*/
public function submitInlineForm(array &$inline_form, FormStateInterface $form_state) {
}
/**
* Runs the inline form validation.
*
* @param array $inline_form
* The inline form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*/
public static function runValidate(array &$inline_form, FormStateInterface $form_state) {
/** @var \Drupal\commerce\Plugin\Commerce\InlineForm\InlineFormInterface $plugin */
$plugin = $inline_form['#inline_form'];
$plugin
->validateInlineForm($inline_form, $form_state);
}
/**
* Runs the inline form submission.
*
* @param array $inline_form
* The inline form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*/
public static function runSubmit(array &$inline_form, FormStateInterface $form_state) {
/** @var \Drupal\commerce\Plugin\Commerce\InlineForm\InlineFormInterface $plugin */
$plugin = $inline_form['#inline_form'];
$plugin
->submitInlineForm($inline_form, $form_state);
}
/**
* Updates the page title based on the inline form's #page_title property.
*
* @param array $inline_form
* The inline form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
* @param array $complete_form
* The complete form structure.
*
* @return array
* The form element.
*/
public static function updatePageTitle(array &$inline_form, FormStateInterface $form_state, array &$complete_form) {
if (!empty($inline_form['#page_title'])) {
$complete_form['#title'] = $inline_form['#page_title'];
}
return $inline_form;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AjaxFormTrait:: |
public static | function | Ajax handler for refreshing an entire form. | |
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 | |
InlineFormBase:: |
public | function |
Builds the inline form. Overrides InlineFormInterface:: |
5 |
InlineFormBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
4 |
InlineFormBase:: |
public | function |
Gets default configuration for this plugin. Overrides ConfigurableInterface:: |
5 |
InlineFormBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
InlineFormBase:: |
public | function |
Gets the inline form label. Overrides InlineFormInterface:: |
|
InlineFormBase:: |
protected | function | Gets the required configuration for this plugin. | 5 |
InlineFormBase:: |
public static | function | Runs the inline form submission. | |
InlineFormBase:: |
public static | function | Runs the inline form validation. | |
InlineFormBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
InlineFormBase:: |
public | function |
Submits the inline form. Overrides InlineFormInterface:: |
4 |
InlineFormBase:: |
public static | function | Updates the page title based on the inline form's #page_title property. | |
InlineFormBase:: |
protected | function | Validates configuration. | 1 |
InlineFormBase:: |
public | function |
Validates the inline form. Overrides InlineFormInterface:: |
5 |
InlineFormBase:: |
public | function |
Constructs a new InlineFormBase object. Overrides PluginBase:: |
4 |
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. | |
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. |