abstract class WebformVariantBase in Webform 6.x
Same name and namespace in other branches
- 8.5 src/Plugin/WebformVariantBase.php \Drupal\webform\Plugin\WebformVariantBase
Provides a base class for a webform variant.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\webform\Plugin\WebformVariantBase implements WebformVariantInterface uses WebformEntityInjectionTrait, WebformPluginSettingsTrait
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of WebformVariantBase
See also
\Drupal\webform\Plugin\WebformVariantInterface
\Drupal\webform\Plugin\WebformVariantManager
\Drupal\webform\Plugin\WebformVariantManagerInterface
5 files declare their use of WebformVariantBase
- BrokenWebformVariant.php in src/
Plugin/ WebformVariant/ BrokenWebformVariant.php - ExampleWebformVariant.php in modules/
webform_example_variant/ src/ Plugin/ WebformVariant/ ExampleWebformVariant.php - OverrideWebformVariant.php in src/
Plugin/ WebformVariant/ OverrideWebformVariant.php - TestWebformOffCanvasWidthVariant.php in tests/
modules/ webform_test_variant/ src/ Plugin/ WebformVariant/ TestWebformOffCanvasWidthVariant.php - TestWebformVariant.php in tests/
modules/ webform_test_variant/ src/ Plugin/ WebformVariant/ TestWebformVariant.php
File
- src/
Plugin/ WebformVariantBase.php, line 19
Namespace
Drupal\webform\PluginView source
abstract class WebformVariantBase extends PluginBase implements WebformVariantInterface {
use WebformEntityInjectionTrait;
use WebformPluginSettingsTrait;
/**
* The webform variant ID.
*
* @var string
*/
protected $variant_id;
/**
* The element key of the webform variant.
*
* @var string
*/
protected $element_key = '';
/**
* The webform variant label.
*
* @var string
*/
protected $label;
/**
* The webform variant notes.
*
* @var string
*/
protected $notes = '';
/**
* The webform variant status.
*
* @var bool
*/
protected $status = 1;
/**
* The weight of the webform variant.
*
* @var int|string
*/
protected $weight = '';
/**
* The configuration factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* {@inheritdoc}
*
* IMPORTANT:
* Webform handlers are initialized and serialized when they are attached to a
* webform. Make sure not include any services as a dependency injection
* that directly connect to the database. This will prevent
* "LogicException: The database connection is not serializable." exceptions
* from being thrown when a form is serialized via an Ajax callback and/or
* form build.
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
$instance = new static($configuration, $plugin_id, $plugin_definition);
$instance->configFactory = $container
->get('config.factory');
$instance
->setConfiguration($configuration);
return $instance;
}
/**
* {@inheritdoc}
*/
public function getSummary() {
return [
'#theme' => 'webform_variant_' . $this->pluginId . '_summary',
'#settings' => $this->configuration,
'#variant' => $this,
];
}
/**
* {@inheritdoc}
*/
public function label() {
return $this
->getLabel();
}
/**
* {@inheritdoc}
*/
public function description() {
return $this->pluginDefinition['description'];
}
/**
* {@inheritdoc}
*/
public function getMachineNameReplacePattern() {
return $this->pluginDefinition['machine_name_replace_pattern'];
}
/**
* {@inheritdoc}
*/
public function getMachineNameReplace() {
return $this->pluginDefinition['machine_name_replace'];
}
/**
* {@inheritdoc}
*/
public function getVariantId() {
return $this->variant_id;
}
/**
* {@inheritdoc}
*/
public function setVariantId($variant_id) {
$this->variant_id = $variant_id;
return $this;
}
/**
* {@inheritdoc}
*/
public function getElementKey() {
return $this->element_key;
}
/**
* {@inheritdoc}
*/
public function setElementKey($element_key) {
$this->element_key = $element_key;
return $this;
}
/**
* {@inheritdoc}
*/
public function setLabel($label) {
$this->label = $label;
return $this;
}
/**
* {@inheritdoc}
*/
public function getLabel() {
return $this->label;
}
/**
* {@inheritdoc}
*/
public function setNotes($notes) {
$this->notes = $notes;
return $this;
}
/**
* {@inheritdoc}
*/
public function getNotes() {
return $this->notes;
}
/**
* {@inheritdoc}
*/
public function setStatus($status) {
$this->status = $status;
return $this;
}
/**
* {@inheritdoc}
*/
public function getStatus() {
return $this->status;
}
/**
* {@inheritdoc}
*/
public function setWeight($weight) {
$this->weight = $weight;
return $this;
}
/**
* {@inheritdoc}
*/
public function getWeight() {
return $this->weight;
}
/**
* {@inheritdoc}
*/
public function enable() {
return $this
->setStatus(TRUE);
}
/**
* {@inheritdoc}
*/
public function disable() {
return $this
->setStatus(FALSE);
}
/**
* {@inheritdoc}
*/
public function isExcluded() {
return $this->configFactory
->get('webform.settings')
->get('variant.excluded_variants.' . $this->pluginDefinition['id']) ? TRUE : FALSE;
}
/**
* {@inheritdoc}
*/
public function isEnabled() {
return $this->status ? TRUE : FALSE;
}
/**
* {@inheritdoc}
*/
public function isDisabled() {
return !$this
->isEnabled();
}
/**
* {@inheritdoc}
*/
public function isApplicable(WebformInterface $webform) {
return TRUE;
}
/**
* {@inheritdoc}
*/
public function getConfiguration() {
return [
'id' => $this
->getPluginId(),
'label' => $this
->getLabel(),
'notes' => $this
->getNotes(),
'variant_id' => $this
->getVariantId(),
'element_key' => $this
->getElementKey(),
'status' => $this
->getStatus(),
'weight' => $this
->getWeight(),
'settings' => $this->configuration,
];
}
/**
* {@inheritdoc}
*/
public function setConfiguration(array $configuration) {
$configuration += [
'variant_id' => '',
'element_key' => '',
'label' => '',
'notes' => '',
'status' => 1,
'weight' => '',
'settings' => [],
];
$this->configuration = $configuration['settings'] + $this
->defaultConfiguration();
$this->variant_id = $configuration['variant_id'];
$this->element_key = $configuration['element_key'];
$this->label = $configuration['label'];
$this->notes = $configuration['notes'];
$this->status = $configuration['status'];
$this->weight = $configuration['weight'];
return $this;
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [];
}
/**
* {@inheritdoc}
*/
public function calculateDependencies() {
return [];
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
return $form;
}
/**
* {@inheritdoc}
*/
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
}
/**
* {@inheritdoc}
*/
public function getOffCanvasWidth() {
return WebformDialogHelper::DIALOG_NORMAL;
}
/**
* {@inheritdoc}
*/
public function applyVariant() {
$webform = $this
->getWebform();
// Do not apply variant if it is not applicable to the webform.
if (!$this
->isApplicable($webform)) {
return FALSE;
}
// Apply variant here.
return TRUE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
protected | property | The messenger. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
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:: |
2 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginBase:: |
public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. | 98 |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
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. | |
WebformEntityInjectionTrait:: |
protected | property | The webform. | 1 |
WebformEntityInjectionTrait:: |
protected | property | The webform submission. | 1 |
WebformEntityInjectionTrait:: |
public | function | Get the webform that this handler is attached to. | |
WebformEntityInjectionTrait:: |
public | function | Set webform and webform submission entity. | |
WebformEntityInjectionTrait:: |
public | function | Reset webform and webform submission entity. | |
WebformEntityInjectionTrait:: |
public | function | ||
WebformEntityInjectionTrait:: |
public | function | Set the webform that this is handler is attached to. | |
WebformEntityInjectionTrait:: |
public | function | Get the webform submission that this handler is handling. | |
WebformPluginSettingsTrait:: |
public | function | ||
WebformPluginSettingsTrait:: |
public | function | ||
WebformPluginSettingsTrait:: |
public | function | ||
WebformPluginSettingsTrait:: |
public | function | ||
WebformVariantBase:: |
protected | property | The configuration factory. | |
WebformVariantBase:: |
protected | property | The element key of the webform variant. | |
WebformVariantBase:: |
protected | property | The webform variant label. | |
WebformVariantBase:: |
protected | property | The webform variant notes. | |
WebformVariantBase:: |
protected | property | The webform variant status. | |
WebformVariantBase:: |
protected | property | The webform variant ID. | |
WebformVariantBase:: |
protected | property | The weight of the webform variant. | |
WebformVariantBase:: |
public | function |
Apply variant to the webform. Overrides WebformVariantInterface:: |
3 |
WebformVariantBase:: |
public | function |
Form constructor. Overrides PluginFormInterface:: |
3 |
WebformVariantBase:: |
public | function | ||
WebformVariantBase:: |
public static | function |
IMPORTANT:
Webform handlers are initialized and serialized when they are attached to a
webform. Make sure not include any services as a dependency injection
that directly connect to the database. This will prevent
"LogicException: The database… Overrides ContainerFactoryPluginInterface:: |
1 |
WebformVariantBase:: |
public | function |
Gets default configuration for this plugin. Overrides ConfigurableInterface:: |
3 |
WebformVariantBase:: |
public | function |
Returns the webform variant description. Overrides WebformVariantInterface:: |
|
WebformVariantBase:: |
public | function |
Disables the webform variant. Overrides WebformVariantInterface:: |
|
WebformVariantBase:: |
public | function |
Enables the webform variant. Overrides WebformVariantInterface:: |
|
WebformVariantBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
WebformVariantBase:: |
public | function |
Returns the element key of the webform variant. Overrides WebformVariantInterface:: |
|
WebformVariantBase:: |
public | function |
Returns the label of the webform variant. Overrides WebformVariantInterface:: |
|
WebformVariantBase:: |
public | function |
Returns the webform variant machine name replacement character. Overrides WebformVariantInterface:: |
|
WebformVariantBase:: |
public | function |
Returns the webform variant machine name replacement pattern. Overrides WebformVariantInterface:: |
|
WebformVariantBase:: |
public | function |
Returns notes of the webform variant. Overrides WebformVariantInterface:: |
|
WebformVariantBase:: |
public | function |
Get configuration form's off-canvas width. Overrides WebformVariantInterface:: |
1 |
WebformVariantBase:: |
public | function |
Returns the status of the webform variant. Overrides WebformVariantInterface:: |
|
WebformVariantBase:: |
public | function |
Returns a render array summarizing the configuration of the webform variant. Overrides WebformVariantInterface:: |
1 |
WebformVariantBase:: |
public | function |
Returns the unique ID representing the webform variant. Overrides WebformVariantInterface:: |
|
WebformVariantBase:: |
public | function |
Returns the weight of the webform variant. Overrides WebformVariantInterface:: |
|
WebformVariantBase:: |
public | function |
Determine if this variant is applicable to the webform. Overrides WebformVariantInterface:: |
2 |
WebformVariantBase:: |
public | function |
Returns the webform variant disabled indicator. Overrides WebformVariantInterface:: |
|
WebformVariantBase:: |
public | function |
Returns the webform variant enabled indicator. Overrides WebformVariantInterface:: |
1 |
WebformVariantBase:: |
public | function |
Checks if the variant is excluded via webform.settings. Overrides WebformVariantInterface:: |
|
WebformVariantBase:: |
public | function |
Returns the webform variant label. Overrides WebformVariantInterface:: |
|
WebformVariantBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
WebformVariantBase:: |
public | function |
Sets the element key of this webform variant. Overrides WebformVariantInterface:: |
|
WebformVariantBase:: |
public | function |
Sets the label for this webform variant. Overrides WebformVariantInterface:: |
|
WebformVariantBase:: |
public | function |
Set notes for this webform variant. Overrides WebformVariantInterface:: |
|
WebformVariantBase:: |
public | function |
Sets the status for this webform variant. Overrides WebformVariantInterface:: |
|
WebformVariantBase:: |
public | function |
Sets the id for this webform variant. Overrides WebformVariantInterface:: |
|
WebformVariantBase:: |
public | function |
Sets the weight for this webform variant. Overrides WebformVariantInterface:: |
|
WebformVariantBase:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
3 |
WebformVariantBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
1 |