class Webform in Webform 8.5
Same name in this branch
- 8.5 src/Element/Webform.php \Drupal\webform\Element\Webform
- 8.5 src/Entity/Webform.php \Drupal\webform\Entity\Webform
- 8.5 src/Plugin/Condition/Webform.php \Drupal\webform\Plugin\Condition\Webform
Same name and namespace in other branches
- 6.x src/Plugin/Condition/Webform.php \Drupal\webform\Plugin\Condition\Webform
Provides a 'Webform' condition.
Plugin annotation
@Condition(
id = "webform",
label = @Translation("Webforms"),
context_definitions = {
"webform" = @ContextDefinition("entity:webform", label = @Translation("Webform"), required = FALSE),
"webform_submission" = @ContextDefinition("entity:webform_submission", label = @Translation("Webform submission"), required = FALSE),
"node" = @ContextDefinition("entity:node", label = @Translation("Node"), required = FALSE),
}
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Component\Plugin\ContextAwarePluginBase implements ContextAwarePluginInterface
- class \Drupal\Core\Plugin\ContextAwarePluginBase implements CacheableDependencyInterface, ContextAwarePluginInterface uses DependencySerializationTrait, StringTranslationTrait, TypedDataTrait
- class \Drupal\Core\Executable\ExecutablePluginBase implements ExecutableInterface
- class \Drupal\Core\Condition\ConditionPluginBase implements ConditionInterface uses ContextAwarePluginAssignmentTrait
- class \Drupal\webform\Plugin\Condition\Webform implements ContainerFactoryPluginInterface
- class \Drupal\Core\Condition\ConditionPluginBase implements ConditionInterface uses ContextAwarePluginAssignmentTrait
- class \Drupal\Core\Executable\ExecutablePluginBase implements ExecutableInterface
- class \Drupal\Core\Plugin\ContextAwarePluginBase implements CacheableDependencyInterface, ContextAwarePluginInterface uses DependencySerializationTrait, StringTranslationTrait, TypedDataTrait
- class \Drupal\Component\Plugin\ContextAwarePluginBase implements ContextAwarePluginInterface
Expanded class hierarchy of Webform
48 string references to 'Webform'
- block_content.type.webform.yml in tests/
modules/ webform_test_block_custom/ config/ install/ block_content.type.webform.yml - tests/modules/webform_test_block_custom/config/install/block_content.type.webform.yml
- field.field.block_content.webform.webform.yml in tests/
modules/ webform_test_block_custom/ config/ install/ field.field.block_content.webform.webform.yml - tests/modules/webform_test_block_custom/config/install/field.field.block_content.webform.webform.yml
- field.field.node.webform.webform.yml in modules/
webform_node/ config/ optional/ field.field.node.webform.webform.yml - modules/webform_node/config/optional/field.field.node.webform.webform.yml
- field.field.node.webform_demo_event.webform.yml in modules/
webform_demo/ webform_demo_event_registration/ config/ install/ field.field.node.webform_demo_event.webform.yml - modules/webform_demo/webform_demo_event_registration/config/install/field.field.node.webform_demo_event.webform.yml
- field.field.node.webform_demo_region.webform.yml in modules/
webform_demo/ webform_demo_region_contact/ config/ install/ field.field.node.webform_demo_region.webform.yml - modules/webform_demo/webform_demo_region_contact/config/install/field.field.node.webform_demo_region.webform.yml
File
- src/
Plugin/ Condition/ Webform.php, line 26
Namespace
Drupal\webform\Plugin\ConditionView source
class Webform extends ConditionPluginBase implements ContainerFactoryPluginInterface {
/**
* The entity storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $entityStorage;
/**
* The webform entity reference manager.
*
* @var \Drupal\webform\WebformEntityReferenceManagerInterface
*/
protected $webformEntityReferenceManager;
/**
* Creates a new Webform instance.
*
* @param array $configuration
* The plugin configuration, i.e. an array with configuration values keyed
* by configuration option name. The special key 'context' may be used to
* initialize the defined contexts by setting it to an array of context
* values keyed by context names.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Entity\EntityStorageInterface $entity_storage
* The entity storage.
* @param \Drupal\webform\WebformEntityReferenceManagerInterface $webform_entity_reference_manager
* The webform entity reference manager.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityStorageInterface $entity_storage, WebformEntityReferenceManagerInterface $webform_entity_reference_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityStorage = $entity_storage;
$this->webformEntityReferenceManager = $webform_entity_reference_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('entity_type.manager')
->getStorage('webform'), $container
->get('webform.entity_reference_manager'));
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$options = [];
$webforms = $this->entityStorage
->loadMultiple();
foreach ($webforms as $webform) {
$options[$webform
->id()] = $webform
->label();
}
$form['webforms'] = [
'#title' => $this
->t('Webform'),
'#description' => $this
->t('Select which webforms this block should be displayed on.'),
'#type' => 'select',
'#options' => $options,
'#multiple' => $options,
'#select2' => TRUE,
'#default_value' => $this->configuration['webforms'],
];
WebformElementHelper::process($form['webforms']);
if (empty($this->configuration['context_mapping'])) {
$form['message'] = [
'#type' => 'webform_message',
'#message_message' => $this
->t('Please make sure to select which entities should be used to determine the current webform.'),
'#message_type' => 'warning',
];
}
$form = parent::buildConfigurationForm($form, $form_state);
// Add helpful descriptions to context mapping.
$form['context_mapping']['webform']['#description'] = $this
->t("Select 'Webform from URL' to display this block, when the current request's path contains the selected webform.");
$form['context_mapping']['webform_submission']['#title'] = $this
->t('Select a @context value:', [
'@context' => $this
->t('webform submission'),
]);
$form['context_mapping']['webform_submission']['#description'] = $this
->t("Select 'Webform submission from URL' to display this block, when the current request's path contains a webform submission that was created from the selected webform.");
$form['context_mapping']['node']['#description'] = $this
->t("Select 'Node from URL' to display this block, when the current request's path contains a node that references the selected webform using a dedicated webform field or node.");
// Attached library to summarize configuration settings.
$form['#attached']['library'][] = 'webform/webform.block';
return $form;
}
/**
* {@inheritdoc}
*/
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValues();
if (!empty($values['webforms']) && empty(array_filter($values['context_mapping']))) {
$form_state
->setErrorByName('webforms', $this
->t('Please select which entity should be used to determine the current webform.'));
}
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValue('webforms') ?: [];
$values = array_filter($values);
$this->configuration['webforms'] = array_combine($values, $values);
parent::submitConfigurationForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function summary() {
if (count($this->configuration['webforms']) > 1) {
$webforms = $this->configuration['webforms'];
$last = array_pop($webforms);
$webforms = implode(', ', $webforms);
return $this
->t('The webform is @webforms or @last', [
'@webforms' => $webforms,
'@last' => $last,
]);
}
$webform = reset($this->configuration['webforms']);
return $this
->t('The webform is @webform', [
'@webform' => $webform,
]);
}
/**
* {@inheritdoc}
*/
public function evaluate() {
if (empty($this->configuration['webforms']) && !$this
->isNegated()) {
return TRUE;
}
elseif ($webform = $this
->getContextWebform()) {
return !empty($this->configuration['webforms'][$webform
->id()]);
}
else {
return FALSE;
}
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [
'webforms' => [],
] + parent::defaultConfiguration();
}
/**
* Gets the webform for a defined context.
*
* @return null|\Drupal\webform\WebformInterface
* The current context's webform.
*/
protected function getContextWebform() {
if ($webform_submission = $this
->getContextValue('webform_submission')) {
return $webform_submission
->getWebform();
}
if ($webform = $this
->getContextValue('webform')) {
return $webform;
}
if ($node = $this
->getContextValue('node')) {
if ($webform_target = $this->webformEntityReferenceManager
->getWebform($node)) {
return $webform_target;
}
}
return NULL;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConditionPluginBase:: |
protected | property | The condition manager to proxy execute calls through. | |
ConditionPluginBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
|
ConditionPluginBase:: |
public | function |
Executes the plugin. Overrides ExecutableInterface:: |
|
ConditionPluginBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
ConditionPluginBase:: |
public | function |
Determines whether condition result will be negated. Overrides ConditionInterface:: |
|
ConditionPluginBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
ConditionPluginBase:: |
public | function |
Sets the executable manager class. Overrides ConditionInterface:: |
|
ContextAwarePluginAssignmentTrait:: |
protected | function | Builds a form element for assigning a context to a given slot. | |
ContextAwarePluginAssignmentTrait:: |
protected | function | Wraps the context handler. | |
ContextAwarePluginAssignmentTrait:: |
abstract protected | function | Ensures the t() method is available. | |
ContextAwarePluginBase:: |
protected | property | The data objects representing the context of this plugin. | |
ContextAwarePluginBase:: |
private | property | Data objects representing the contexts passed in the plugin configuration. | |
ContextAwarePluginBase:: |
protected | function |
Overrides ContextAwarePluginBase:: |
|
ContextAwarePluginBase:: |
public | function |
The cache contexts associated with this object. Overrides CacheableDependencyInterface:: |
9 |
ContextAwarePluginBase:: |
public | function |
The maximum age for which this object may be cached. Overrides CacheableDependencyInterface:: |
7 |
ContextAwarePluginBase:: |
public | function |
The cache tags associated with this object. Overrides CacheableDependencyInterface:: |
4 |
ContextAwarePluginBase:: |
public | function |
This code is identical to the Component in order to pick up a different
Context class. Overrides ContextAwarePluginBase:: |
|
ContextAwarePluginBase:: |
public | function |
Overrides ContextAwarePluginBase:: |
|
ContextAwarePluginBase:: |
public | function |
Overrides ContextAwarePluginBase:: |
|
ContextAwarePluginBase:: |
public | function |
Gets a mapping of the expected assignment names to their context names. Overrides ContextAwarePluginInterface:: |
|
ContextAwarePluginBase:: |
public | function |
Gets the defined contexts. Overrides ContextAwarePluginInterface:: |
|
ContextAwarePluginBase:: |
public | function |
Gets the value for a defined context. Overrides ContextAwarePluginInterface:: |
|
ContextAwarePluginBase:: |
public | function |
Gets the values for all defined contexts. Overrides ContextAwarePluginInterface:: |
|
ContextAwarePluginBase:: |
public | function |
Set a context on this plugin. Overrides ContextAwarePluginBase:: |
|
ContextAwarePluginBase:: |
public | function |
Sets a mapping of the expected assignment names to their context names. Overrides ContextAwarePluginInterface:: |
|
ContextAwarePluginBase:: |
public | function |
Sets the value for a defined context. Overrides ContextAwarePluginBase:: |
|
ContextAwarePluginBase:: |
public | function |
Validates the set values for the defined contexts. Overrides ContextAwarePluginInterface:: |
|
ContextAwarePluginBase:: |
public | function | Implements magic __get() method. | |
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 | |
ExecutablePluginBase:: |
public | function | Gets all configuration values. | |
ExecutablePluginBase:: |
public | function | Gets the definition of a configuration option. | |
ExecutablePluginBase:: |
public | function | Gets an array of definitions of available configuration options. | |
ExecutablePluginBase:: |
public | function | Sets the value of a particular configuration option. | |
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 |
TypedDataTrait:: |
protected | property | The typed data manager used for creating the data types. | |
TypedDataTrait:: |
public | function | Gets the typed data manager. | 2 |
TypedDataTrait:: |
public | function | Sets the typed data manager. | 2 |
Webform:: |
protected | property | The entity storage. | |
Webform:: |
protected | property | The webform entity reference manager. | |
Webform:: |
public | function |
Form constructor. Overrides ConditionPluginBase:: |
|
Webform:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
Webform:: |
public | function |
Gets default configuration for this plugin. Overrides ConditionPluginBase:: |
|
Webform:: |
public | function |
Evaluates the condition and returns TRUE or FALSE accordingly. Overrides ConditionInterface:: |
|
Webform:: |
protected | function | Gets the webform for a defined context. | |
Webform:: |
public | function |
Form submission handler. Overrides ConditionPluginBase:: |
|
Webform:: |
public | function |
Provides a human readable summary of the condition's configuration. Overrides ConditionInterface:: |
|
Webform:: |
public | function |
Form validation handler. Overrides ConditionPluginBase:: |
|
Webform:: |
public | function |
Creates a new Webform instance. Overrides ConditionPluginBase:: |