Commit f6d1b880 authored by jrockowitz's avatar jrockowitz Committed by jrockowitz

Issue #3055254 by jrockowitz: Expose submission states as a token

parent 494f3c9e
......@@ -263,8 +263,9 @@ interface WebformSubmissionInterface extends ContentEntityInterface, EntityOwner
* Track the state of a submission.
*
* @return string
* Either STATE_NEW, STATE_DRAFT, STATE_COMPLETED, STATE_UPDATED, or
* STATE_CONVERTED depending on the last save operation performed.
* Either SSTATE_UNSAVED, STATE_DRAFT, STATE_COMPLETED, STATE_UPDATED,
* STATE_LOCKED, or STATE_CONVERTED depending on the last
* save operation performed.
*/
public function getState();
......
......@@ -51,6 +51,8 @@ elements: |
Langcode: [webform_submission:langcode]
Language: [webform_submission:language]
In draft: [webform_submission:in-draft]
State: [webform_submission:state]
State (label): [webform_submission:state:label]
Completed page: [webform_submission:completed-page]
Source URL: [webform_submission:source-url]
Submitted to: [webform_submission:submitted-to]
......
......@@ -90,6 +90,14 @@ function webform_token_info() {
'name' => t('In draft'),
'description' => t('Is the webform submission in draft.'),
];
$webform_submission['state'] = [
'name' => t('State'),
'description' => t('The state of the webform submission. (Unsaved, Draft, Completed, Updated, Locked, or Converted)'),
];
$webform_submission['state:raw'] = [
'name' => t('State (Raw value)'),
'description' => t('The state raw value untranslated of the webform submission. (unsaved, draft, completed, updated, locked, or converted)'),
];
$webform_submission['label'] = [
'name' => t('Label'),
'description' => t('The label of the webform submission.'),
......@@ -441,7 +449,23 @@ function webform_tokens($type, $tokens, array $data, array $options, BubbleableM
break;
case 'in-draft':
$replacements[$original] = $webform_submission->in_draft->value ? t('Yes') : t('No');
$replacements[$original] = $webform_submission->isDraft() ? t('Yes') : t('No');
break;
case 'state':
$replacements[$original] = $webform_submission->getState();
break;
case 'state:label':
$states = [
WebformSubmissionInterface::STATE_DRAFT => t('Draft'),
WebformSubmissionInterface::STATE_COMPLETED => t('Completed'),
WebformSubmissionInterface::STATE_CONVERTED => t('Converted'),
WebformSubmissionInterface::STATE_UPDATED => t('Updated'),
WebformSubmissionInterface::STATE_UNSAVED => t('Unsaved'),
WebformSubmissionInterface::STATE_LOCKED => t('Locked'),
];
$replacements[$original] = $states[$webform_submission->getState()];
break;
case 'current-page':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment