class WebformSubmissionViews in Webform 8.5
Same name and namespace in other branches
- 6.x src/Element/WebformSubmissionViews.php \Drupal\webform\Element\WebformSubmissionViews
Provides a form element for selecting webform submission views.
Plugin annotation
@FormElement("webform_submission_views");
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\Core\Render\Element\FormElement implements FormElementInterface
- class \Drupal\webform\Element\WebformMultiple
- class \Drupal\webform\Element\WebformSubmissionViews
- class \Drupal\webform\Element\WebformMultiple
- class \Drupal\Core\Render\Element\FormElement implements FormElementInterface
- class \Drupal\Core\Render\Element\RenderElement implements ElementInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of WebformSubmissionViews
2 #type uses of WebformSubmissionViews
- WebformAdminConfigSubmissionsForm::buildForm in src/
Form/ AdminConfig/ WebformAdminConfigSubmissionsForm.php - Form constructor.
- WebformEntitySettingsSubmissionsForm::form in src/
EntitySettings/ WebformEntitySettingsSubmissionsForm.php - Gets the actual form array to be built.
File
- src/
Element/ WebformSubmissionViews.php, line 14
Namespace
Drupal\webform\ElementView source
class WebformSubmissionViews extends WebformMultiple {
/**
* {@inheritdoc}
*/
public static function processWebformMultiple(&$element, FormStateInterface $form_state, &$complete_form) {
if (!\Drupal::moduleHandler()
->moduleExists('views')) {
$element['#element_validate'] = [
[
get_called_class(),
'emptyValue',
],
];
return $element;
}
$element['#key'] = 'name';
$element['#header'] = TRUE;
$element['#empty_items'] = 0;
$element['#min_items'] = 1;
$element['#add_more_input_label'] = t('more submission views');
// Build element.
$element['#element'] = [];
// Name / Title / View.
$view_options = [];
/** @var \Drupal\views\ViewEntityInterface[] $views */
$views = View::loadMultiple();
foreach ($views as $view) {
// Only include webform submission views.
if ($view
->get('base_table') !== 'webform_submission' || $view
->get('base_field') !== 'sid') {
continue;
}
$optgroup = $view
->label();
$displays = $view
->get('display');
foreach ($displays as $display_id => $display) {
// Only include embed displays.
if ($display['display_plugin'] === 'embed') {
$view_options[$optgroup][$view
->id() . ':' . $display_id] = $optgroup . ': ' . $display['display_title'];
}
}
}
$element['#element']['name_title_view'] = [
'#type' => 'container',
'#title' => t('View / Name / Title'),
'#help' => '<b>' . t('View') . ':</b> ' . t('A webform submission embed display. The selected view should also include contextual filters. {webform_id}/{source_entity_type}/{source_entity_id}/{account_id}/{in_draft}') . '<hr/>' . '<b>' . t('Name') . ':</b> ' . t('The name to be displayed in the URL when there are multiple submission views available.') . '<hr/>' . '<b>' . t('Options') . ':</b> ' . t('The title to be display in the dropdown menu when there are multiple submission views available.'),
'view' => [
'#type' => 'select',
'#title' => t('View'),
'#title_display' => 'invisible',
'#empty_option' => t('Select view…'),
'#options' => $view_options,
'#error_no_message' => TRUE,
],
'name' => [
'#type' => 'textfield',
'#title' => t('Name'),
'#title_display' => 'invisible',
'#placeholder' => t('Enter name…'),
'#size' => 20,
'#pattern' => '^[-_a-z0-9]+$',
'#error_no_message' => TRUE,
],
'title' => [
'#type' => 'textfield',
'#title' => t('Title'),
'#title_display' => 'invisible',
'#placeholder' => t('Enter title…'),
'#size' => 20,
'#error_no_message' => TRUE,
],
];
// Global routes.
if (!empty($element['#global'])) {
$global_route_options = [
'entity.webform_submission.collection' => t('Submissions'),
'entity.webform_submission.user' => t('User'),
];
$element['#element']['global_routes'] = [
'#type' => 'checkboxes',
'#title' => t('Apply to global'),
'#help' => t('Display the selected view on the below paths') . '<hr/><b>' . t('Submissions') . ':</b><br/>/admin/structure/webform/submissions/manage' . '<hr/><b>' . t('User') . ':</b><br/>/user/{user}/submissions',
'#options' => $global_route_options,
'#element_validate' => [
[
'\\Drupal\\webform\\Utility\\WebformElementHelper',
'filterValues',
],
],
'#error_no_message' => TRUE,
];
}
// Webform routes.
$webform_route_options = [
'entity.webform.results_submissions' => t('Submissions'),
'entity.webform.user.drafts' => t('User drafts'),
'entity.webform.user.submissions' => t('User submissions'),
];
$element['#element']['webform_routes'] = [
'#type' => 'checkboxes',
'#title' => t('Apply to webform'),
'#help' => t('Display the selected view on the below paths') . '<hr/><b>' . t('Submissions') . ':</b><br/>/admin/structure/webform/manage/{webform}/results/submissions' . '<hr/><b>' . t('User drafts') . ':</b><br/>/webform/{webform}/drafts' . '<hr/><b>' . t('User submissions') . ':</b><br/>/webform/{webform}/submissions',
'#options' => $webform_route_options,
'#element_validate' => [
[
'\\Drupal\\webform\\Utility\\WebformElementHelper',
'filterValues',
],
],
'#error_no_message' => TRUE,
];
// Node routes.
if (\Drupal::moduleHandler()
->moduleExists('webform_node')) {
$node_route_options = [
'entity.node.webform.results_submissions' => t('Submissions'),
'entity.node.webform.user.drafts' => t('User drafts'),
'entity.node.webform.user.submissions' => t('User submissions'),
];
$element['#element']['node_routes'] = [
'#type' => 'checkboxes',
'#title' => t('Apply to node'),
'#help' => t('Display the selected view on the below paths') . '<hr/><b>' . t('Submissions') . ':</b><br/>/node/{node}/webform/results/submissions' . '<hr/>' . '<b>' . t('User drafts') . ':</b><br/>/node/{node}/webform/drafts' . '<hr/>' . '<b>' . t('User submissions') . ':</b><br/>/node/{node}/webform/submissions',
'#options' => $node_route_options,
'#element_validate' => [
[
'\\Drupal\\webform\\Utility\\WebformElementHelper',
'filterValues',
],
],
'#error_no_message' => TRUE,
];
}
parent::processWebformMultiple($element, $form_state, $complete_form);
return $element;
}
/**
* {@inheritdoc}
*/
public static function validateWebformMultiple(&$element, FormStateInterface $form_state, &$complete_form) {
if (!\Drupal::moduleHandler()
->moduleExists('views')) {
$element['#value'] = [];
$form_state
->setValueForElement($element, []);
return;
}
parent::validateWebformMultiple($element, $form_state, $complete_form);
$items = NestedArray::getValue($form_state
->getValues(), $element['#parents']);
foreach ($items as $name => &$item) {
// Remove empty view references.
if ($name === '' && empty($item['view']) && empty($item['global_routes']) && empty($item['webform_routes']) && empty($item['node_routes'])) {
unset($items[$name]);
continue;
}
if ($name === '') {
$form_state
->setError($element, t('Name is required.'));
}
if (empty($item['title'])) {
$form_state
->setError($element, t('Title is required.'));
}
if (empty($item['view'])) {
$form_state
->setError($element, t('View name/display id is required.'));
}
}
$element['#value'] = $items;
$form_state
->setValueForElement($element, $items);
}
/**
* Form validate callback which clears the submitted value.
*/
public static function emptyValue(&$element, FormStateInterface $form_state, &$complete_form) {
$element['#value'] = [];
$form_state
->setValueForElement($element, []);
}
}
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 | |
FormElement:: |
public static | function | Adds autocomplete functionality to elements. | |
FormElement:: |
public static | function | #process callback for #pattern form element property. | |
FormElement:: |
public static | function | #element_validate callback for #pattern form element property. | |
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. | |
WebformMultiple:: |
public static | function | Webform submission handler for adding more items. | |
WebformMultiple:: |
public static | function | Webform submission handler for adding an item. | |
WebformMultiple:: |
public static | function | Webform submission Ajax callback the returns the list table. | |
WebformMultiple:: |
protected static | function | Build a single element header. | |
WebformMultiple:: |
protected static | function | Build a single element row. | |
WebformMultiple:: |
protected static | function | Build an element's title with help. | |
WebformMultiple:: |
constant | Value indicating a element accepts an unlimited number of values. | ||
WebformMultiple:: |
public static | function | Convert an array containing of values (elements or _item_ and weight) to an array of items. | |
WebformMultiple:: |
public static | function | Convert value array containing (elements or _item_ and weight) to an item. | |
WebformMultiple:: |
public | function |
Returns the element properties for this element. Overrides ElementInterface:: |
|
WebformMultiple:: |
public static | function | Get unique key used to store the number of items for an element. | |
WebformMultiple:: |
protected static | function | Determine if any sub-element is required. | |
WebformMultiple:: |
protected static | function | Initialize element. | |
WebformMultiple:: |
protected static | function | Initialize, prepare, and finalize composite sub-elements recursively. | |
WebformMultiple:: |
public static | function | Check if array is empty. | |
WebformMultiple:: |
protected static | function | Determine if an element is hidden. | |
WebformMultiple:: |
public static | function | Webform submission handler for removing an item. | |
WebformMultiple:: |
protected static | function | Set element row default value recursively. | |
WebformMultiple:: |
protected static | function | Set element row default value recursively. | |
WebformMultiple:: |
protected static | function | Set element row parents recursively. | |
WebformMultiple:: |
protected static | function | Validate composite element has unique keys. | |
WebformMultiple:: |
public static | function |
Determines how user input is mapped to an element's #value property. Overrides FormElement:: |
|
WebformSubmissionViews:: |
public static | function | Form validate callback which clears the submitted value. | |
WebformSubmissionViews:: |
public static | function |
Process items and build multiple elements widget. Overrides WebformMultiple:: |
|
WebformSubmissionViews:: |
public static | function |
Validates webform multiple element. Overrides WebformMultiple:: |