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/Element/Webform.php \Drupal\webform\Element\Webform
Provides a render element to display a webform.
Plugin annotation
@RenderElement("webform");
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\Core\Render\Element\RenderElement implements ElementInterface
- class \Drupal\webform\Element\Webform
- class \Drupal\Core\Render\Element\RenderElement implements ElementInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of Webform
1 file declares its use of Webform
- WebformEntityController.php in src/
Controller/ WebformEntityController.php
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
4 #type uses of Webform
- WebformBlock::build in src/
Plugin/ Block/ WebformBlock.php - Builds and returns the renderable array for this block plugin.
- WebformEntityReferenceEntityFormatter::viewElements in src/
Plugin/ Field/ FieldFormatter/ WebformEntityReferenceEntityFormatter.php - Builds a renderable array for a field value.
- WebformShareController::page in modules/
webform_share/ src/ Controller/ WebformShareController.php - Returns a webform to be shared as the page of an iframe.
- WebformTestElementController::index in tests/
modules/ webform_test_element/ src/ Controller/ WebformTestElementController.php - Returns the webform test element page.
File
- src/
Element/ Webform.php, line 16
Namespace
Drupal\webform\ElementView source
class Webform extends RenderElement {
/**
* {@inheritdoc}
*/
public function getInfo() {
$class = get_class($this);
return [
'#pre_render' => [
[
$class,
'preRenderWebformElement',
],
],
'#webform' => NULL,
'#default_data' => [],
'#action' => NULL,
'#sid' => NULL,
'#information' => NULL,
];
}
/**
* Webform element pre render callback.
*/
public static function preRenderWebformElement($element) {
$webform = $element['#webform'] instanceof WebformInterface ? $element['#webform'] : WebformEntity::load($element['#webform']);
if (!$webform) {
return $element;
}
if (!empty($element['#sid'])) {
$webform_submission = WebformSubmission::load($element['#sid']);
if ($webform_submission && $webform_submission
->access('update') && $webform_submission
->getWebform()
->id() === $webform
->id()) {
$element['webform_build'] = \Drupal::service('entity.form_builder')
->getForm($webform_submission, 'edit');
}
elseif ($webform
->getSetting('form_access_denied') !== WebformInterface::ACCESS_DENIED_DEFAULT) {
// Set access denied message.
$element['webform_access_denied'] = static::buildAccessDenied($webform);
}
else {
static::addCacheableDependency($element, $webform);
}
}
else {
if ($webform
->access('submission_create')) {
$values = [];
// Set data.
$values['data'] = $element['#default_data'];
// Set source entity type and id.
if (!empty($element['#entity']) && $element['#entity'] instanceof EntityInterface) {
$values['entity_type'] = $element['#entity']
->getEntityTypeId();
$values['entity_id'] = $element['#entity']
->id();
}
elseif (!empty($element['#entity_type']) && !empty($element['#entity_id'])) {
$values['entity_type'] = $element['#entity_type'];
$values['entity_id'] = $element['#entity_id'];
}
// Build the webform.
$element['webform_build'] = $webform
->getSubmissionForm($values);
}
elseif ($webform
->getSetting('form_access_denied') !== WebformInterface::ACCESS_DENIED_DEFAULT) {
// Set access denied message.
$element['webform_access_denied'] = static::buildAccessDenied($webform);
}
else {
static::addCacheableDependency($element, $webform);
}
}
if (isset($element['webform_build'])) {
// Set custom form submit action.
if (!empty($element['#action'])) {
$element['webform_build']['#action'] = $element['#action'];
}
// Hide submission information.
if ($element['#information'] === FALSE && isset($element['webform_build']['information'])) {
$element['webform_build']['information']['#access'] = FALSE;
}
}
// Allow anonymous drafts to be restored.
// @see \Drupal\webform\WebformSubmissionForm::buildForm
if (\Drupal::currentUser()
->isAnonymous() && $webform
->getSetting('draft') === WebformInterface::DRAFT_ALL) {
$element['#cache']['max-age'] = 0;
// @todo Remove once bubbling of element's max-age to page cache is fixed.
// @see https://www.drupal.org/project/webform/issues/3015760
// @see https://www.drupal.org/project/drupal/issues/2352009
if (\Drupal::moduleHandler()
->moduleExists('page_cache')) {
\Drupal::service('page_cache_kill_switch')
->trigger();
}
}
return $element;
}
/**
* Build access denied message for a webform.
*
* @param \Drupal\webform\WebformInterface $webform
* A webform.
*
* @return array
* A renderable array containing thea access denied message for a webform.
*/
public static function buildAccessDenied(WebformInterface $webform) {
/** @var \Drupal\webform\WebformTokenManagerInterface $webform_token_manager */
$webform_token_manager = \Drupal::service('webform.token_manager');
// Message.
$config = \Drupal::configFactory()
->get('webform.settings');
$message = $webform
->getSetting('form_access_denied_message') ?: $config
->get('settings.default_form_access_denied_message');
$message = $webform_token_manager
->replace($message, $webform);
// Attributes.
$attributes = $webform
->getSetting('form_access_denied_attributes');
$attributes['class'][] = 'webform-access-denied';
$build = [
'#type' => 'container',
'#attributes' => $attributes,
'message' => WebformHtmlEditor::checkMarkup($message),
];
return static::addCacheableDependency($build, $webform);
}
/**
* Adds webform.settings and webform as cache dependencies to a render array.
*
* @param array &$elements
* The render array to update.
* @param \Drupal\webform\WebformInterface $webform
* A webform.
*
* @return array
* A render array with webform.settings and webform as cache dependencies.
*/
public static function addCacheableDependency(array &$elements, WebformInterface $webform) {
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = \Drupal::service('renderer');
// Track if webform.settings is updated.
$config = \Drupal::configFactory()
->get('webform.settings');
$renderer
->addCacheableDependency($elements, $config);
// Track if the webform is updated.
$renderer
->addCacheableDependency($elements, $webform);
return $elements;
}
}
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. | |
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. | |
PluginBase:: |
public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. | 92 |
RenderElement:: |
public static | function | Adds Ajax information about an element to communicate with JavaScript. | |
RenderElement:: |
public static | function | Adds members of this group as actual elements for rendering. | |
RenderElement:: |
public static | function | Form element processing handler for the #ajax form property. | 1 |
RenderElement:: |
public static | function | Arranges elements into groups. | |
RenderElement:: |
public static | function |
Sets a form element's class attribute. Overrides ElementInterface:: |
|
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. | |
Webform:: |
public static | function | Adds webform.settings and webform as cache dependencies to a render array. | |
Webform:: |
public static | function | Build access denied message for a webform. | |
Webform:: |
public | function |
Returns the element properties for this element. Overrides ElementInterface:: |
|
Webform:: |
public static | function | Webform element pre render callback. |