Commit 253e6ded authored by jrockowitz's avatar jrockowitz Committed by jrockowitz

Issue #3094270 by jrockowitz: Add support for webform variants

parent 7ec6cbc8
......@@ -98,6 +98,8 @@ assets:
javascript: ''
handler:
excluded_handlers: { }
variant:
excluded_variants: { }
export:
temp_directory: ''
exporter: delimited
......
......@@ -491,6 +491,35 @@
label: Weight
settings:
type: 'webform.handler.[%parent.id]'
variants:
type: sequence
label: 'Webform variants'
sequence:
type: mapping
mapping:
id:
type: string
label: 'Variant plugin ID'
variant_id:
type: string
label: 'Variant instance ID'
element_key:
type: string
label: 'Variant element key'
label:
type: label
label: Label
notes:
type: text
label: Notes
status:
type: boolean
label: Status
weight:
type: integer
label: Weight
settings:
type: 'webform.variant.[%parent.id]'
third_party_settings:
type: sequence
label: 'Third party settings'
......
'webform.variants.*':
type: mapping
label: 'Variants settings'
# Setting, elements, and handlers mapping copied from webform.webform.*.
# @see webform_config_schema_info_alter()
webform.variant.override:
type: mapping
label: Override
mapping:
debug:
label: Debug
type: string
......@@ -479,6 +479,13 @@ webform.settings:
excluded_handlers:
type: ignore
label: 'Excluded submission handlers'
variant:
type: mapping
label: 'Variant settings'
mapping:
excluded_variants:
type: ignore
label: 'Excluded webform variants'
batch:
type: mapping
label: 'Batch settings'
......
......@@ -195,3 +195,31 @@ a:focus .webform-icon-locked--off {
display: table-cell;
}
}
/**
* Variants table.
* @see /admin/structure/webform/manage/{webform_id}/variants
*/
.webform-variants-table .ajax-progress-throbber {
display: none;
}
.webform-variants-table .webform-variant-table-test-multiple td {
border-top: 1px solid #a6a6a6;
border-bottom: 1px solid #a6a6a6;
background-color: #f5f5f2;
}
@media screen and (max-width: 1280px) {
.js-off-canvas-dialog-open .webform-variants-table th,
.js-off-canvas-dialog-open .webform-variants-table td {
display: none;
}
.js-off-canvas-dialog-open .webform-variants-table th:first-child,
.js-off-canvas-dialog-open .webform-variants-table th:last-child,
.js-off-canvas-dialog-open .webform-variants-table td:first-child,
.js-off-canvas-dialog-open .webform-variants-table td:last-child {
display: table-cell;
}
}
......@@ -6,6 +6,7 @@
* @see /admin/structure/webform/manage/{webform}/results/submissions
* @see /admin/structure/webform/manage/{webform}
* @see /admin/structure/webform/manage/{webform}/handlers
* @see /admin/structure/webform/manage/{webform}/variants
*/
/**
......
......@@ -80,6 +80,7 @@ echo 'true' > modules/webform_examples_accessibility/webform_examples_accessibil
echo 'true' > modules/webform_example_element/webform_example_element.features.yml
echo 'true' > modules/webform_example_composite/webform_example_composite.features.yml
echo 'true' > modules/webform_example_handler/webform_example_handler.features.yml
echo 'true' > modules/webform_example_variant/webform_example_variant.features.yml
echo 'true' > modules/webform_example_element/webform_example_remote_post.features.yml
echo 'true' > modules/webform_group/tests/modules/webform_group_test/webform_group_test.features.yml
......@@ -151,6 +152,7 @@ drush en -y webform\
webform_examples_accessibility\
webform_example_element\
webform_example_handler\
webform_example_variant\
webform_example_remote_post\
webform_group_test\
webform_image_select\
......@@ -203,6 +205,7 @@ drush features-export -y webform_examples_accessibility
drush features-export -y webform_example_element
drush features-export -y webform_example_composite
drush features-export -y webform_example_handler
drush features-export -y webform_example_variant
drush features-export -y webform_example_remote_post
drush features-export -y webform_group_test
drush features-export -y webform_image_select
......@@ -254,6 +257,7 @@ drush webform:tidy -y --dependencies webform_examples_accessibility
drush webform:tidy -y --dependencies webform_example_element
drush webform:tidy -y --dependencies webform_example_composite
drush webform:tidy -y --dependencies webform_example_handler
drush webform:tidy -y --dependencies webform_example_variant
drush webform:tidy -y --dependencies webform_example_remote_post
drush webform:tidy -y --dependencies webform_group_test
drush webform:tidy -y --dependencies webform_icheck
......@@ -302,6 +306,7 @@ drush features-import -y webform_examples_accessibility
drush features-import -y webform_example_element
drush features-import -y webform_example_composite
drush features-import -y webform_example_handler
drush features-import -y webform_example_variant
drush features-import -y webform_example_remote_post
drush features-import -y webform_entity_print
drush features-import -y webform_group_test
......
......@@ -115,6 +115,7 @@ function _webform_update_webform_setting(array $data) {
'settings' => [],
'access' => [],
'handlers' => [],
'variants' => [],
];
$default_settings = Webform::getDefaultSettings();
......
......@@ -3431,3 +3431,11 @@ function webform_update_8183() {
}
}
}
/**
* Issue #3094270: Add webform variants support.
*/
function webform_update_8184() {
_webform_update_admin_settings();
_webform_update_webform_settings();
}
......@@ -34,6 +34,7 @@ function webform_theme() {
'webform_actions' => [
'render element' => 'element',
],
'webform_handler_action_summary' => [
'variables' => ['settings' => NULL, 'handler' => NULL],
],
......@@ -50,6 +51,10 @@ function webform_theme() {
'variables' => ['settings' => NULL, 'handler' => NULL],
],
'webform_variant_override_summary' => [
'variables' => ['settings' => NULL, 'variant' => NULL],
],
'webform_confirmation' => [
'variables' => ['webform' => NULL, 'source_entity' => NULL, 'webform_submission' => NULL],
],
......
......@@ -268,6 +268,13 @@
// @see https://stackoverflow.com/questions/6944744/javascript-get-portion-of-url-path
var a = document.createElement('a');
a.href = response.url;
var forceReload = (response.url.match(/\?reload=([^&]+)($|&)/)) ? RegExp.$1 : null;
if (forceReload) {
response.url = response.url.replace(/\?reload=([^&]+)($|&)/, '');
this.redirect(ajax, response, status);
return;
}
if (a.pathname === window.location.pathname && $('.webform-ajax-refresh').length) {
updateKey = (response.url.match(/[?|&]update=([^&]+)($|&)/)) ? RegExp.$1 : null;
addElement = (response.url.match(/[?|&]add_element=([^&]+)($|&)/)) ? RegExp.$1 : null;
......@@ -281,7 +288,6 @@
Drupal.behaviors.webformUnsaved.clear();
}
this.redirect(ajax, response, status);
}
};
......
langcode: en
status: open
dependencies:
enforced:
module:
- webform_example_variant
open: null
close: null
weight: 0
uid: null
template: false
archive: false
id: webform_example_variant_ab_test
title: 'Example: Variant: A/B test'
description: 'A feedback form with an A/B test.'
category: ''
elements: |
mode:
'#type': webform_variant
'#title': Variant
'#randomize': true
'#variant': override
type:
'#title': 'Type of Feedback'
'#type': webform_radios_other
'#required': true
'#options':
Comments: Comments
'Report a Bug': 'Report a Bug'
Questions: Questions
'#options_display': side_by_side
comments:
'#type': textarea
'#title': 'Your Feedback'
'#required': true
name:
'#title': 'Your Name'
'#type': textfield
'#required': true
email:
'#title': 'Your Email'
'#type': email
'#required': true
actions:
'#type': webform_actions
'#title': 'Submit button(s)'
'#submit__label': 'Submit feedback'
css: ''
javascript: ''
settings:
ajax: false
ajax_scroll_top: form
ajax_progress_type: ''
ajax_effect: ''
ajax_speed: null
page: true
page_submit_path: ''
page_confirm_path: ''
page_admin_theme: false
form_title: source_entity_webform
form_submit_once: false
form_exception_message: ''
form_open_message: ''
form_close_message: ''
form_previous_submissions: true
form_confidential: false
form_confidential_message: ''
form_remote_addr: true
form_convert_anonymous: false
form_prepopulate: false
form_prepopulate_source_entity: false
form_prepopulate_source_entity_required: false
form_prepopulate_source_entity_type: ''
form_reset: false
form_disable_autocomplete: false
form_novalidate: false
form_disable_inline_errors: false
form_required: false
form_unsaved: false
form_disable_back: false
form_submit_back: false
form_autofocus: false
form_details_toggle: false
form_access_denied: default
form_access_denied_title: ''
form_access_denied_message: ''
form_access_denied_attributes: { }
form_file_limit: ''
submission_label: ''
submission_log: false
submission_views: { }
submission_views_replace: { }
submission_user_columns: { }
submission_user_duplicate: false
submission_access_denied: default
submission_access_denied_title: ''
submission_access_denied_message: ''
submission_access_denied_attributes: { }
submission_exception_message: ''
submission_locked_message: ''
submission_excluded_elements: { }
submission_exclude_empty: false
submission_exclude_empty_checkbox: false
previous_submission_message: ''
previous_submissions_message: ''
autofill: false
autofill_message: ''
autofill_excluded_elements: { }
wizard_progress_bar: true
wizard_progress_pages: false
wizard_progress_percentage: false
wizard_progress_link: false
wizard_progress_states: false
wizard_start_label: ''
wizard_preview_link: false
wizard_confirmation: true
wizard_confirmation_label: ''
wizard_track: ''
preview: 0
preview_label: ''
preview_title: ''
preview_message: ''
preview_attributes: { }
preview_excluded_elements: { }
preview_exclude_empty: true
preview_exclude_empty_checkbox: false
draft: none
draft_multiple: false
draft_auto_save: false
draft_saved_message: ''
draft_loaded_message: ''
draft_pending_single_message: ''
draft_pending_multiple_message: ''
confirmation_type: page
confirmation_title: ''
confirmation_message: 'Thank you for your feedback.'
confirmation_url: '<front>'
confirmation_attributes: { }
confirmation_back: true
confirmation_back_label: ''
confirmation_back_attributes: { }
confirmation_exclude_query: false
confirmation_exclude_token: true
confirmation_update: false
limit_total: null
limit_total_interval: null
limit_total_message: ''
limit_total_unique: false
limit_user: null
limit_user_interval: null
limit_user_message: ''
limit_user_unique: false
entity_limit_total: null
entity_limit_total_interval: null
entity_limit_user: null
entity_limit_user_interval: null
purge: none
purge_days: null
results_disabled: false
results_disabled_ignore: false
token_view: false
token_update: false
access:
create:
roles:
- anonymous
- authenticated
users: { }
permissions: { }
view_any:
roles: { }
users: { }
permissions: { }
update_any:
roles: { }
users: { }
permissions: { }
delete_any:
roles: { }
users: { }
permissions: { }
purge_any:
roles: { }
users: { }
permissions: { }
view_own:
roles: { }
users: { }
permissions: { }
update_own:
roles: { }
users: { }
permissions: { }
delete_own:
roles: { }
users: { }
permissions: { }
administer:
roles: { }
users: { }
permissions: { }
test:
roles: { }
users: { }
permissions: { }
configuration:
roles: { }
users: { }
permissions: { }
handlers:
email_confirmation:
id: email
label: 'Email confirmation'
handler_id: email_confirmation
status: true
conditions: { }
weight: 1
settings:
states:
- completed
to_mail: '[webform_submission:values:email:raw]'
to_options: { }
cc_mail: ''
cc_options: { }
bcc_mail: ''
bcc_options: { }
from_mail: _default
from_options: { }
from_name: _default
subject: _default
body: '[webform_submission:values:comments:value]'
excluded_elements: { }
ignore_access: false
exclude_empty: true
exclude_empty_checkbox: false
html: true
attachments: false
twig: false
theme_name: ''
parameters: { }
debug: false
reply_to: ''
return_path: ''
sender_mail: ''
sender_name: ''
email_notification:
id: email
label: 'Email notification'
handler_id: email_notification
status: true
conditions: { }
weight: 2
settings:
states:
- completed
to_mail: '[webform_submission:values:type:raw]'
to_options:
- value: Comments
text: '[site:mail]'
- value: 'Report a Bug'
text: '[site:mail]'
- value: Questions
text: '[site:mail]'
- value: _other_
text: '[site:mail]'
- value: _default
text: '[site:mail]'
cc_mail: ''
cc_options: { }
bcc_mail: ''
bcc_options: { }
from_mail: '[webform_submission:values:email:raw]'
from_options: { }
from_name: '[webform_submission:values:name:raw]'
subject: _default
body: '[webform_submission:values:comments:value]'
excluded_elements: { }
ignore_access: false
exclude_empty: true
exclude_empty_checkbox: false
html: true
attachments: false
twig: false
theme_name: ''
parameters: { }
debug: false
reply_to: ''
return_path: ''
sender_mail: ''
sender_name: ''
variants:
a:
id: override
label: A
notes: ''
variant_id: a
element_key: mode
status: true
weight: 1
settings:
settings: { }
override_settings:
definitions:
table: ''
elements: |
type:
'#title_display': 'inline'
'#type': webform_select_other
'#options_display': null
comments:
'#title_display': 'inline'
name:
'#title_display': 'inline'
email:
'#title_display': 'inline'
actions:
'#title': 'Submit'
handlers:
email_confirmation:
status: false
email_notification:
status: false
debug: false
b:
id: override
label: B
notes: ''
variant_id: b
element_key: mode
status: true
weight: 1
settings:
settings:
preview: 1
override_settings:
definitions:
table: ''
elements: ''
handlers:
email_confirmation:
settings:
body: _default
debug: true
email_notification:
settings:
body: _default
debug: true
debug: false
langcode: en
status: open
dependencies:
enforced:
module:
- webform_example_variant
module:
- webform_example_variant
open: null
close: null
weight: 0
uid: null
template: false
archive: false
id: webform_example_variant_segments
title: 'Example: Variant: Segments'
description: 'An example of a long/short form with organization variants.'
category: Example
elements: |
form_type:
'#type': webform_variant
'#title': 'Form type'
'#variant': example
'#display_on': both
organization:
'#type': webform_variant
'#title': Organization
'#variant': example
'#display_on': both
description:
'#type': webform_markup
'#markup': ''
notes:
'#type': textfield
'#title': Notes
css: ''
javascript: ''
settings:
ajax: false
ajax_scroll_top: form
ajax_progress_type: ''
ajax_effect: ''
ajax_speed: null
page: true
page_submit_path: ''
page_confirm_path: ''
page_admin_theme: false
form_title: source_entity_webform
form_submit_once: false
form_exception_message: ''
form_open_message: ''
form_close_message: ''
form_previous_submissions: true
form_confidential: false
form_confidential_message: ''
form_remote_addr: true
form_convert_anonymous: false
form_prepopulate: false
form_prepopulate_source_entity: false
form_prepopulate_source_entity_required: false
form_prepopulate_source_entity_type: ''
form_reset: false
form_disable_autocomplete: false
form_novalidate: false
form_disable_inline_errors: false
form_required: false
form_unsaved: false
form_disable_back: false
form_submit_back: false