Commit 249fb76f authored by jrockowitz's avatar jrockowitz Committed by jrockowitz

Issue #3064070 by jrockowitz: [Webform 8.x-5.4] Split STATE_DRAFT into...

Issue #3064070 by jrockowitz: [Webform 8.x-5.4] Split STATE_DRAFT into STATE_DRAFT_CREATED and STATE_DRAFT_UPDATE
parent 932d70bc
......@@ -164,11 +164,17 @@ webform.handler.remote_post:
deleted_custom_data:
label: 'Deleted custom data'
type: string
draft_url:
label: 'Draft URL'
draft_created_url:
label: 'Draft created URL'
type: uri
draft_custom_data:
label: 'Draft custom data'
draft_created_custom_data:
label: 'Draft created custom data'
type: string
draft_updated_url:
label: 'Draft updated URL'
type: uri
draft_updated_custom_data:
label: 'Draft updated custom data'
type: string
converted_url:
label: 'Converted URL'
......
......@@ -3120,8 +3120,56 @@ function webform_update_8168() {
}
/**
* Issue #3062308: Add the ability to use admin theme for a webform's canonical route
* Issue #3062308: Add the ability to use admin theme for a webform's canonical route.
*/
function webform_update_8169() {
_webform_update_webform_settings();
}
/**
* Issue #3064070: Split STATE_DRAFT into STATE_DRAFT_CREATED and STATE_DRAFT_UPDATE.
*/
function webform_update_8170() {
// List of handler is that use webform submission state.
$states_handler_ids = ['action', 'email', 'scheduled_email', 'remote_post'];
$config_factory = \Drupal::configFactory();
foreach ($config_factory->listAll('webform.webform.') as $webform_config_name) {
$webform_config = $config_factory->getEditable($webform_config_name);
$data = $webform_config->getRawData();
$handler_updated = FALSE;
foreach ($data['handlers'] as &$handler) {
$settings = $handler['settings'];
if (!in_array($handler['id'], $states_handler_ids)) {
}
if (isset($settings['states'])
&& is_array($settings['states'])
&& in_array('draft', $settings['states'])) {
// Remove old 'draft' state.
WebformArrayHelper::removeValue($settings['states'], 'draft');
// Prepend new 'draft_created' and 'draft_updated' states.
$settings['states'] = array_merge(['draft_created', 'draft_updated'], $settings['states']);
}
if ($handler['id'] === 'remote_post'
&& isset($settings['draft_url'])) {
$settings['draft_created_url'] = $settings['draft_url'];
$settings['draft_created_custom_data'] = $settings['draft_custom_data'];
$settings['draft_updated_url'] = $settings['draft_url'];
$settings['draft_updated_custom_data'] = $settings['draft_custom_data'];
unset($settings['draft_url']);
unset($settings['draft_custom_data']);
}
if ($handler['settings'] != $settings) {
$handler_updated = TRUE;
$handler['settings'] = $settings;
}
}
if ($handler_updated) {
$webform_config->setData($data)->save();
}
}
}
......@@ -39,7 +39,7 @@ elements: |
'#title': 'Confirmation number'
'#type': value
'#value': '[webform:handler:remote_post:completed:confirmation_number]'
css: ''
javascript: ''
settings:
......@@ -129,7 +129,7 @@ settings:
confirmation_title: ''
confirmation_message: |
<p>Your confirmation number is [webform_submission:values:confirmation_number].</p>
confirmation_url: ''
confirmation_attributes: { }
confirmation_back: true
......@@ -235,23 +235,25 @@ handlers:
confirmation_number: confirmation_number
custom_data: |
custom_all: true
custom_options: ''
debug: true
completed_url: '[site:url]webform_example_remote_post/completed'
completed_custom_data: |
custom_completed: true
updated_url: '[site:url]webform_example_remote_post/updated'
updated_custom_data: |
custom_updated: true
deleted_url: '[site:url]webform_example_remote_post/deleted'
deleted_custom_data: |
custom_deleted: true
draft_url: ''
draft_custom_data: ''
draft_created_url: ''
draft_created_custom_data: ''
draft_updated_url: ''
draft_updated_custom_data: ''
converted_url: ''
converted_custom_data: ''
message: ''
......
......@@ -39,7 +39,7 @@ elements: |
visible:
':input[name="send"]':
value: other
css: ''
javascript: ''
settings:
......@@ -374,7 +374,8 @@ handlers:
weight: -45
settings:
states:
- draft
- draft_created
- draft_updated
- completed
- updated
to_mail: '[webform_submission:values:send:raw]'
......@@ -417,7 +418,8 @@ handlers:
weight: -47
settings:
states:
- draft
- draft_created
- draft_updated
to_mail: '[webform_submission:values:send:raw]'
to_options:
- value: draft_reminder
......
......@@ -611,12 +611,12 @@ class WebformSubmission extends ContentEntityBase implements WebformSubmissionIn
return self::STATE_CONVERTED;
}
elseif ($this->isDraft()) {
return self::STATE_DRAFT;
return ($this->created->value === $this->changed->value) ? self::STATE_DRAFT_CREATED : self::STATE_DRAFT_UPDATED;
}
elseif ($this->isLocked()) {
return self::STATE_LOCKED;
}
elseif ($this->completed->value == $this->changed->value) {
elseif ($this->completed->value === $this->changed->value) {
return self::STATE_COMPLETED;
}
else {
......
......@@ -70,7 +70,8 @@ class ActionWebformHandler extends WebformHandlerBase {
// Get state labels.
$states = [
WebformSubmissionInterface::STATE_DRAFT => $this->t('Draft Saved'),
WebformSubmissionInterface::STATE_DRAFT_CREATED => $this->t('Draft created'),
WebformSubmissionInterface::STATE_DRAFT_UPDATED => $this->t('Draft updated'),
WebformSubmissionInterface::STATE_CONVERTED => $this->t('Converted'),
WebformSubmissionInterface::STATE_COMPLETED => $this->t('Completed'),
WebformSubmissionInterface::STATE_UPDATED => $this->t('Updated'),
......@@ -127,10 +128,11 @@ class ActionWebformHandler extends WebformHandlerBase {
'#type' => 'checkboxes',
'#title' => $this->t('Execute'),
'#options' => [
WebformSubmissionInterface::STATE_DRAFT => $this->t('…when <b>draft</b> is saved.'),
WebformSubmissionInterface::STATE_CONVERTED => $this->t('…when anonymous submission is <b>converted</b> to authenticated.'),
WebformSubmissionInterface::STATE_COMPLETED => $this->t('…when submission is <b>completed</b>.'),
WebformSubmissionInterface::STATE_UPDATED => $this->t('…when submission is <b>updated</b>.'),
WebformSubmissionInterface::STATE_DRAFT_CREATED => $this->t('…when <b>draft is created</b>.'),
WebformSubmissionInterface::STATE_DRAFT_UPDATED => $this->t('…when <b>draft is updated</b>.'),
WebformSubmissionInterface::STATE_CONVERTED => $this->t('…when anonymous <b>submission is converted</b> to authenticated.'),
WebformSubmissionInterface::STATE_COMPLETED => $this->t('…when <b>submission is completed</b>.'),
WebformSubmissionInterface::STATE_UPDATED => $this->t('…when <b>submission is updated</b>.'),
],
'#required' => TRUE,
'#access' => $results_disabled ? FALSE : TRUE,
......
......@@ -188,7 +188,8 @@ class EmailWebformHandler extends WebformHandlerBase implements WebformHandlerMe
// Set state.
$states = [
WebformSubmissionInterface::STATE_DRAFT => $this->t('Draft Saved'),
WebformSubmissionInterface::STATE_DRAFT_CREATED => $this->t('Draft created'),
WebformSubmissionInterface::STATE_DRAFT_UPDATED => $this->t('Draft updated'),
WebformSubmissionInterface::STATE_CONVERTED => $this->t('Converted'),
WebformSubmissionInterface::STATE_COMPLETED => $this->t('Completed'),
WebformSubmissionInterface::STATE_UPDATED => $this->t('Updated'),
......@@ -716,12 +717,13 @@ class EmailWebformHandler extends WebformHandlerBase implements WebformHandlerMe
'#type' => 'checkboxes',
'#title' => $this->t('Send email'),
'#options' => [
WebformSubmissionInterface::STATE_DRAFT => $this->t('…when <b>draft</b> is saved.'),
WebformSubmissionInterface::STATE_CONVERTED => $this->t('…when anonymous submission is <b>converted</b> to authenticated.'),
WebformSubmissionInterface::STATE_COMPLETED => $this->t('…when submission is <b>completed</b>.'),
WebformSubmissionInterface::STATE_UPDATED => $this->t('…when submission is <b>updated</b>.'),
WebformSubmissionInterface::STATE_DELETED => $this->t('…when submission is <b>deleted</b>.'),
WebformSubmissionInterface::STATE_LOCKED => $this->t('…when submission is <b>locked</b>.'),
WebformSubmissionInterface::STATE_DRAFT_CREATED => $this->t('…when <b>draft is created</b>.'),
WebformSubmissionInterface::STATE_DRAFT_UPDATED => $this->t('…when <b>draft is updated</b>.'),
WebformSubmissionInterface::STATE_CONVERTED => $this->t('…when anonymous <b>submission is converted</b> to authenticated.'),
WebformSubmissionInterface::STATE_COMPLETED => $this->t('…when <b>submission is completed</b>.'),
WebformSubmissionInterface::STATE_UPDATED => $this->t('…when <b>submission is updated</b>.'),
WebformSubmissionInterface::STATE_DELETED => $this->t('…when <b>submission is deleted</b>.'),
WebformSubmissionInterface::STATE_LOCKED => $this->t('…when <b>submission is locked</b>.'),
],
'#access' => $results_disabled ? FALSE : TRUE,
'#default_value' => $results_disabled ? [WebformSubmissionInterface::STATE_COMPLETED] : $this->configuration['states'],
......
......@@ -131,7 +131,8 @@ class RemotePostWebformHandler extends WebformHandlerBase {
$settings['deleted_url'] = '';
}
if (!$this->isDraftEnabled()) {
$settings['draft_url'] = '';
$settings['draft_created_url'] = '';
$settings['draft_updated_url'] = '';
}
if (!$this->isConvertEnabled()) {
$settings['converted_url'] = '';
......@@ -162,8 +163,10 @@ class RemotePostWebformHandler extends WebformHandlerBase {
'updated_custom_data' => '',
'deleted_url' => '',
'deleted_custom_data' => '',
'draft_url' => '',
'draft_custom_data' => '',
'draft_created_url' => '',
'draft_created_custom_data' => '',
'draft_updated_url' => '',
'draft_updated_custom_data' => '',
'converted_url' => '',
'converted_custom_data' => '',
// Custom error response messages.
......@@ -185,31 +188,37 @@ class RemotePostWebformHandler extends WebformHandlerBase {
WebformSubmissionInterface::STATE_COMPLETED => [
'state' => $this->t('completed'),
'label' => $this->t('Completed'),
'description' => $this->t('Post data when submission is <b>completed</b>.'),
'description' => $this->t('Post data when <b>submission is completed</b>.'),
'access' => TRUE,
],
WebformSubmissionInterface::STATE_UPDATED => [
'state' => $this->t('updated'),
'label' => $this->t('Updated'),
'description' => $this->t('Post data when submission is <b>updated</b>.'),
'description' => $this->t('Post data when <b>submission is updated</b>.'),
'access' => $this->isResultsEnabled(),
],
WebformSubmissionInterface::STATE_DELETED => [
'state' => $this->t('deleted'),
'label' => $this->t('Deleted'),
'description' => $this->t('Post data when submission is <b>deleted</b>.'),
'description' => $this->t('Post data when <b>submission is deleted</b>.'),
'access' => $this->isResultsEnabled(),
],
WebformSubmissionInterface::STATE_DRAFT => [
'state' => $this->t('draft'),
'label' => $this->t('Draft'),
'description' => $this->t('Post data when <b>draft</b> is saved.'),
WebformSubmissionInterface::STATE_DRAFT_CREATED => [
'state' => $this->t('draft created'),
'label' => $this->t('Draft created'),
'description' => $this->t('Post data when <b>draft is created.</b>'),
'access' => $this->isDraftEnabled(),
],
WebformSubmissionInterface::STATE_DRAFT_UPDATED => [
'state' => $this->t('draft updated'),
'label' => $this->t('Draft updated'),
'description' => $this->t('Post data when <b>draft is updated.</b>'),
'access' => $this->isDraftEnabled(),
],
WebformSubmissionInterface::STATE_CONVERTED => [
'state' => $this->t('converted'),
'label' => $this->t('Converted'),
'description' => $this->t('Post data when anonymous submission is <b>converted</b> to authenticated.'),
'description' => $this->t('Post data when anonymous <b>submission is converted</b> to authenticated.'),
'access' => $this->isConvertEnabled(),
],
];
......@@ -424,19 +433,21 @@ class RemotePostWebformHandler extends WebformHandlerBase {
*
* @param string $state
* The state of the webform submission.
* Either STATE_NEW, STATE_DRAFT, STATE_COMPLETED, STATE_UPDATED, or
* STATE_CONVERTED depending on the last save operation performed.
* Either STATE_NEW, STATE_DRAFT_CREATED, STATE_DRAFT_UPDATED,
* STATE_COMPLETED, STATE_UPDATED, or STATE_CONVERTED
* depending on the last save operation performed.
* @param \Drupal\webform\WebformSubmissionInterface $webform_submission
* The webform submission to be posted.
*/
protected function remotePost($state, WebformSubmissionInterface $webform_submission) {
if (empty($this->configuration[$state . '_url'])) {
$state_url = $state . '_url';
if (empty($this->configuration[$state_url])) {
return;
}
$this->messageManager->setWebformSubmission($webform_submission);
$request_url = $this->configuration[$state . '_url'];
$request_url = $this->configuration[$state_url];
$request_url = $this->replaceTokens($request_url, $webform_submission);
$request_method = (!empty($this->configuration['method'])) ? $this->configuration['method'] : 'POST';
$request_type = ($request_method !== 'GET') ? $this->configuration['type'] : NULL;
......@@ -502,8 +513,9 @@ class RemotePostWebformHandler extends WebformHandlerBase {
*
* @param string $state
* The state of the webform submission.
* Either STATE_NEW, STATE_DRAFT, STATE_COMPLETED, STATE_UPDATED, or
* STATE_CONVERTED depending on the last save operation performed.
* Either STATE_NEW, STATE_DRAFT_CREATED, STATE_DRAFT_UPDATED,
* STATE_COMPLETED, STATE_UPDATED, or STATE_CONVERTED
* depending on the last save operation performed.
* @param \Drupal\webform\WebformSubmissionInterface $webform_submission
* The webform submission to be posted.
*
......@@ -682,8 +694,9 @@ class RemotePostWebformHandler extends WebformHandlerBase {
* Message to be displayed.
* @param string $state
* The state of the webform submission.
* Either STATE_NEW, STATE_DRAFT, STATE_COMPLETED, STATE_UPDATED, or
* STATE_CONVERTED depending on the last save operation performed.
* Either STATE_NEW, STATE_DRAFT_CREATED, STATE_DRAFT_UPDATED,
* STATE_COMPLETED, STATE_UPDATED, or STATE_CONVERTED
* depending on the last save operation performed.
* @param string $request_url
* The remote URL the request is being posted to.
* @param string $request_method
......@@ -829,8 +842,9 @@ class RemotePostWebformHandler extends WebformHandlerBase {
*
* @param string $state
* The state of the webform submission.
* Either STATE_NEW, STATE_DRAFT, STATE_COMPLETED, STATE_UPDATED, or
* STATE_CONVERTED depending on the last save operation performed.
* Either STATE_NEW, STATE_DRAFT_CREATED, STATE_DRAFT_UPDATED,
* STATE_COMPLETED, STATE_UPDATED, or STATE_CONVERTED
* depending on the last save operation performed.
* @param string $message
* Message to be displayed.
* @param string $request_url
......
......@@ -109,12 +109,12 @@ options:
// Check 'draft' operation.
$this->postSubmission($webform, [], t('Save Draft'));
$this->assertRaw("form_params:
custom_draft: true
custom_draft_created: true
custom_data: true
response_type: '200'
first_name: John
last_name: Smith");
$this->assertRaw('Processed draft request.');
$this->assertRaw('Processed draft_created request.');
// Login root user.
$this->drupalLogin($this->rootUser);
......
......@@ -18,10 +18,20 @@ interface WebformSubmissionInterface extends ContentEntityInterface, EntityOwner
const STATE_UNSAVED = 'unsaved';
/**
* Return status for submission in draft.
* Return status for submission in draft created.
*/
const STATE_DRAFT = 'draft';
/**
* Return status for submission in draft created.
*/
const STATE_DRAFT_CREATED = 'draft_created';
/**
* Return status for submission in draft updated.
*/
const STATE_DRAFT_UPDATED = 'draft_updated';
/**
* Return status for submission that has been completed.
*/
......@@ -263,9 +273,9 @@ interface WebformSubmissionInterface extends ContentEntityInterface, EntityOwner
* Track the state of a submission.
*
* @return string
* Either SSTATE_UNSAVED, STATE_DRAFT, STATE_COMPLETED, STATE_UPDATED,
* STATE_LOCKED, or STATE_CONVERTED depending on the last
* save operation performed.
* Either STATE_UNSAVED, STATE_DRAFT_CREATED, STATE_DRAFT_UPDATED,
* STATE_COMPLETED, STATE_UPDATED, STATE_LOCKED, or STATE_CONVERTED
* depending on the last save operation performed.
*/
public function getState();
......
......@@ -947,7 +947,8 @@ class WebformSubmissionStorage extends SqlContentEntityStorage implements Webfor
'webform_submission' => $entity,
];
switch ($entity->getState()) {
case WebformSubmissionInterface::STATE_DRAFT:
case WebformSubmissionInterface::STATE_DRAFT_UPDATED:
case WebformSubmissionInterface::STATE_DRAFT_CREATED:
if ($update) {
$message = '@title draft updated.';
$context['operation'] = 'draft updated';
......@@ -998,8 +999,12 @@ class WebformSubmissionStorage extends SqlContentEntityStorage implements Webfor
elseif (!$webform->getSetting('results_disabled')) {
// Log general events to the 'webform'.
switch ($entity->getState()) {
case WebformSubmissionInterface::STATE_DRAFT:
$message = '@title draft saved.';
case WebformSubmissionInterface::STATE_DRAFT_CREATED:
$message = '@title draft created.';
break;
case WebformSubmissionInterface::STATE_DRAFT_UPDATED:
$message = '@title draft updated.';
break;
case WebformSubmissionInterface::STATE_UPDATED:
......
......@@ -47,7 +47,7 @@ elements: |
'#attributes':
readonly: readonly
style: 'background-color: #eee'
css: ''
javascript: ''
settings:
......@@ -221,7 +221,8 @@ handlers:
weight: -48
settings:
states:
- draft
- draft_created
- draft_updated
- completed
- updated
notes: '[webform_submission:values:notes_add]'
......@@ -230,7 +231,7 @@ handlers:
data: |
notes_add: ''
notes_last: '[webform_submission:values:notes_add]'
message: 'Submission notes have been updated.'
message_type: status
debug: true
......@@ -246,7 +247,8 @@ handlers:
weight: -50
settings:
states:
- draft
- draft_created
- draft_updated
- converted
- completed
- updated
......@@ -269,7 +271,8 @@ handlers:
weight: -49
settings:
states:
- draft
- draft_created
- draft_updated
- converted
- completed
- updated
......@@ -292,7 +295,8 @@ handlers:
weight: -52
settings:
states:
- draft
- draft_created
- draft_updated
- converted
- completed
- updated
......
......@@ -17,7 +17,7 @@ category: 'Test: Handler'
elements: |
message:
'#markup': 'Click ''Save Draft'' and ''Submit'' to send emails triggered by submissions state.'
css: ''
javascript: ''
settings:
......@@ -188,7 +188,8 @@ handlers:
weight: 0
settings:
states:
- draft
- draft_created
- draft_updated
to_mail: draft@example.com
to_options: { }
cc_mail: ''
......
......@@ -37,7 +37,7 @@ elements: |
'#title': 'Confirmation number'
'#type': value
'#value': '[webform:handler:remote_post:completed:confirmation_number]'
css: ''
javascript: ''
settings:
......@@ -127,7 +127,7 @@ settings:
confirmation_title: ''
confirmation_message: |
<p>Your confirmation number is [webform_submission:values:confirmation_number].</p>
confirmation_url: ''
confirmation_attributes: { }
confirmation_back: true
......@@ -234,32 +234,36 @@ handlers:
confirmation_number: confirmation_number
custom_data: |
custom_data: true
custom_options: |
headers:
custom_header: 'true'
debug: true
completed_url: 'http://webform-test-handler-remote-post/completed'
completed_custom_data: |
custom_completed: true
updated_url: 'http://webform-test-handler-remote-post/updated'
updated_custom_data: |
custom_updated: true
deleted_url: 'http://webform-test-handler-remote-post/deleted'
deleted_custom_data: |
custom_deleted: true
draft_url: 'http://webform-test-handler-remote-post/draft'
draft_custom_data: |
custom_draft: true
draft_created_url: 'http://webform-test-handler-remote-post/draft_created'
draft_created_custom_data: |
custom_draft_created: true
draft_updated_url: 'http://webform-test-handler-remote-post/draft_updated'
draft_updated_custom_data: |
custom_draft_updated: true
converted_url: 'http://webform-test-handler-remote-post/converted'
converted_custom_data: |
custom_converted: true
message: ''
messages: { }
error_url: ''
......@@ -38,7 +38,7 @@ elements: |
'#title': 'Confirmation number'
'#type': value
'#value': '[webform:handler:remote_post:completed:confirmation_number]'
css: ''
javascript: ''
settings:
......@@ -128,7 +128,7 @@ settings:
confirmation_title: ''
confirmation_message: |
<p>Your confirmation number is [webform_submission:values:confirmation_number].</p>
confirmation_url: ''
confirmation_attributes: { }
confirmation_back: true
......@@ -235,33 +235,37 @@ handlers:
confirmation_number: confirmation_number
custom_data: |
custom_data: true
custom_options: |
headers:
'Accept-Language': '[webform_submission:langcode]'
custom_header: 'true'
debug: true
completed_url: 'http://webform-test-handler-remote-post/completed'
completed_custom_data: |
custom_completed: true
updated_url: 'http://webform-test-handler-remote-post/updated'
updated_custom_data: |
custom_updated: true
deleted_url: 'http://webform-test-handler-remote-post/deleted'
deleted_custom_data: |
custom_deleted: true
draft_url: 'http://webform-test-handler-remote-post/draft'
draft_custom_data: |
custom_draft: true
draft_created_url: 'http://webform-test-handler-remote-post/draft_created'
draft_created_custom_data: |
custom_draft_created: true
draft_updated_url: 'http://webform-test-handler-remote-post/draft_updated'
draft_updated_custom_data: |
custom_draft_updated: true
converted_url: 'http://webform-test-handler-remote-post/converted'
converted_custom_data: |
custom_converted: true
message: ''
messages:
- code: 401
......
......@@ -26,7 +26,7 @@ elements: |
'#required': true
'#multiple': true
'#file_extensions': txt
css: ''
javascript: ''
settings:
......@@ -116,7 +116,7 @@ settings:
confirmation_title: ''
confirmation_message: |
<p>Your confirmation number is [webform_submission:values:confirmation_number].</p>
confirmation_url: ''
confirmation_attributes: { }
confirmation_back: true
......@@ -230,8 +230,10 @@ handlers:
updated_custom_data: ''
deleted_url: 'http://webform-test-handler-remote-post/deleted'
deleted_custom_data: ''
draft_url: 'http://webform-test-handler-remote-post/draft'
draft_custom_data: ''
draft_created_url: 'http://webform-test-handler-remote-post/draft_created'
draft_created_custom_data: ''
draft_updated_url: 'http://webform-test-handler-remote-post/draft_updated'
draft_updated_custom_data: ''
converted_url: 'http://webform-test-handler-remote-post/converted'
converted_custom_data: ''
message: ''
......
......@@ -37,7 +37,7 @@ elements: |
'#title': 'Confirmation number'
'#type': value
'#value': '[webform:handler:remote_post:completed:confirmation_number]'
css: ''
javascript: ''
settings:
......@@ -127,7 +127,7 @@ settings:
confirmation_title: ''
confirmation_message: |
<p>Your confirmation number is [webform_submission:values:confirmation_number].</p>
confirmation_url: ''
confirmation_attributes: { }
confirmation_back: true
......@@ -234,32 +234,36 @@ handlers:
confirmation_number: confirmation_number
custom_data: |
custom_data: true