From fb6c1c53007ff249592f0b9f67d6df1b86fe2555 Mon Sep 17 00:00:00 2001 From: Mikkel Ricky Date: Fri, 19 Aug 2022 12:21:28 +0200 Subject: [PATCH 01/14] DW-568: Added support for inheriting values without creating a submission --- .gitignore | 4 +- composer.json | 8 +- os2forms_forloeb.module | 10 ++ .../EngineTasks/MaestroWebformInheritTask.php | 94 +++++++++++++++---- 4 files changed, 96 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index 93aceb7..b9f063a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ # Ignore IntelliJ -.idea/* \ No newline at end of file +.idea/* +composer.lock +vendor diff --git a/composer.json b/composer.json index 4c22192..bad238c 100644 --- a/composer.json +++ b/composer.json @@ -100,6 +100,12 @@ ] }, "config": { - "sort-packages": true + "sort-packages": true, + "allow-plugins": { + "cweagans/composer-patches": true, + "zaporylie/composer-drupal-optimizations": true, + "dealerdirect/phpcodesniffer-composer-installer": true, + "simplesamlphp/composer-module-installer": true + } } } diff --git a/os2forms_forloeb.module b/os2forms_forloeb.module index 3296639..d34fcf8 100644 --- a/os2forms_forloeb.module +++ b/os2forms_forloeb.module @@ -13,6 +13,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\BubbleableMetadata; use Drupal\Core\Url; use Drupal\maestro\Engine\MaestroEngine; +use Drupal\os2forms_forloeb\Plugin\EngineTasks\MaestroWebformInheritTask; use Drupal\webform\Entity\WebformSubmission; use Drupal\user\Entity\User; @@ -343,3 +344,12 @@ function os2forms_forloeb_maestro_post_fetch_assigned_queue_tasks($userID, &$que $queueIDs = array_unique($queueIDs); } } + +/** + * Implements hook_webform_element_alter(). + * + * @see MaestroWebformInheritTask::webformElementAlter() + */ +function os2forms_forloeb_webform_element_alter(array &$element, FormStateInterface $form_state, array $context) { + MaestroWebformInheritTask::webformElementAlter($element, $form_state, $context); +} diff --git a/src/Plugin/EngineTasks/MaestroWebformInheritTask.php b/src/Plugin/EngineTasks/MaestroWebformInheritTask.php index 83dbdb9..6702421 100644 --- a/src/Plugin/EngineTasks/MaestroWebformInheritTask.php +++ b/src/Plugin/EngineTasks/MaestroWebformInheritTask.php @@ -74,6 +74,12 @@ public function getTaskEditForm(array $task, $templateMachineName) { '#default_value' => $task['data']['inherit_webform_unique_id'] ?? '', '#required' => TRUE, ]; + $form['inherit_webform_create_submission'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Create submission'), + '#description' => $this->t('Create submission'), + '#default_value' => $task['data']['inherit_webform_create_submission'] ?? FALSE, + ]; return $form; } @@ -86,6 +92,7 @@ public function prepareTaskForSave(array &$form, FormStateInterface $form_state, parent::prepareTaskForSave($form, $form_state, $task); // Add custom field(s) to the inherited prepareTaskForSave method. $task['data']['inherit_webform_unique_id'] = $form_state->getValue('inherit_webform_unique_id'); + $task['data']['inherit_webform_create_submission'] = $form_state->getValue('inherit_webform_create_submission'); } /** @@ -120,35 +127,47 @@ public function getExecutableForm($modal, MaestroExecuteInteractive $parent) { } // Now create webform submission, submit and attach to current process. $templateTask = MaestroEngine::getTemplateTaskByQueueID($this->queueID); - $taskUniqueSubmissionId = $templateTask['data']['unique_id']; $webformMachineName = $templateTask['data']['webform_machine_name']; $values = []; $values['webform_id'] = $webformMachineName; $values['data'] = $field_values; - // Create submission. - $new_submission = WebformSubmission::create($values); + $createSubmission = $task['data']['inherit_webform_create_submission'] ?? FALSE; + if ($createSubmission) { + // Create submission. + $new_submission = WebformSubmission::create($values); + + // Submit the webform submission. + $submission = WebformSubmissionForm::submitWebformSubmission($new_submission); + + // WebformSubmissionForm::submitWebformSubmission returns an array + // if the submission is not valid. + if (is_array($submission)) { + \Drupal::logger('os2forms_forloeb')->error( + "Can't create new submission: " . json_encode($submission) + ); + \Drupal::messenger()->addError('Webform data is invalid and could not be submitted.'); + return FALSE; + } - // Submit the webform submission. - $submission = WebformSubmissionForm::submitWebformSubmission($new_submission); + $taskUniqueSubmissionId = $templateTask['data']['unique_id']; - // WebformSubmissionForm::submitWebformSubmission returns an array - // if the submission is not valid. - if (is_array($submission)) { - \Drupal::logger('os2forms_forloeb')->error( - "Can't create new submission: " . json_encode($submission) + // Attach it to the Maestro process. + $sid = $new_submission->id(); + MaestroEngine::createEntityIdentifier( + $this->processID, $new_submission->getEntityTypeId(), + $new_submission->bundle(), $taskUniqueSubmissionId, $sid ); - \Drupal::messenger()->addError('Webform data is invalid and could not be submitted.'); - return FALSE; } + else { + // Store values in session. + $values['processID'] = $this->processID; + $values['queueID'] = $this->queueID; + $values['webformInheritID'] = $webformInheritID; - // Attach it to the Maestro process. - $sid = $new_submission->id(); - MaestroEngine::createEntityIdentifier( - $this->processID, $new_submission->getEntityTypeId(), - $new_submission->bundle(), $taskUniqueSubmissionId, $sid - ); + self::setTaskValues($this->queueID, $values); + } $form = parent::getExecutableForm($modal, $parent); // Catch os2forms-forloeb access token and pass it further. @@ -164,4 +183,43 @@ public function getExecutableForm($modal, MaestroExecuteInteractive $parent) { return $form; } + /** + * Implements hook_webform_element_alter(). + */ + public static function webformElementAlter(array &$element, FormStateInterface $form_state, array $context) { + $request = \Drupal::request(); + $isMaestro = (bool) $request->query->get('maestro', 0); + $queueID = (int) $request->query->get('queueid', 0); + if ($isMaestro && $queueID > 0) { + $values = self::getTaskValues($queueID); + $elementId = $element['#webform_key']; + if (isset($values['data'][$elementId])) { + $element['#default_value'] = $values['data'][$elementId]; + } + } + } + + /** + * Get task values from session. + */ + private static function getTaskValues($queueID) { + $sessionKey = self::getTaskValuesSessionKey($queueID); + return \Drupal::request()->getSession()->get($sessionKey); + } + + /** + * Set task values in session. + */ + private static function setTaskValues($queueID, $values) { + $sessionKey = self::getTaskValuesSessionKey($queueID); + \Drupal::request()->getSession()->set($sessionKey, $values); + } + + /** + * Get task values session key. + */ + private static function getTaskValuesSessionKey(int $queueID) { + return sprintf('os2forms_forloeb_inherited_values_%s', $queueID); + } + } From 589c21b77740c38c0cab065c0bebcb21c7599cf1 Mon Sep 17 00:00:00 2001 From: Mikkel Ricky Date: Thu, 22 Sep 2022 13:03:00 +0200 Subject: [PATCH 02/14] DW-568: Handled flow tokens --- .../EngineTasks/MaestroWebformInheritTask.php | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/Plugin/EngineTasks/MaestroWebformInheritTask.php b/src/Plugin/EngineTasks/MaestroWebformInheritTask.php index 6702421..703e0e9 100644 --- a/src/Plugin/EngineTasks/MaestroWebformInheritTask.php +++ b/src/Plugin/EngineTasks/MaestroWebformInheritTask.php @@ -133,6 +133,8 @@ public function getExecutableForm($modal, MaestroExecuteInteractive $parent) { $values['webform_id'] = $webformMachineName; $values['data'] = $field_values; + $form = parent::getExecutableForm($modal, $parent); + $createSubmission = $task['data']['inherit_webform_create_submission'] ?? FALSE; if ($createSubmission) { // Create submission. @@ -159,6 +161,16 @@ public function getExecutableForm($modal, MaestroExecuteInteractive $parent) { $this->processID, $new_submission->getEntityTypeId(), $new_submission->bundle(), $taskUniqueSubmissionId, $sid ); + + // Catch os2forms-forloeb access token and pass it further. + if ($form instanceof RedirectResponse && $token = \Drupal::request()->query->get('os2forms-forloeb-ws-token')) { + // Check token to previous submission and update it to new one. + if ($token === $webform_submission->getToken()) { + $token = $new_submission->getToken(); + $url = Url::fromUserInput($form->getTargetUrl(), ['query' => ['os2forms-forloeb-ws-token' => $token]]); + $form = new RedirectResponse($url->toString()); + } + } } else { // Store values in session. @@ -169,17 +181,6 @@ public function getExecutableForm($modal, MaestroExecuteInteractive $parent) { self::setTaskValues($this->queueID, $values); } - $form = parent::getExecutableForm($modal, $parent); - // Catch os2forms-forloeb access token and pass it further. - if ($form instanceof RedirectResponse && $token = \Drupal::request()->query->get('os2forms-forloeb-ws-token')) { - // Check token to previous submission and update it to new one. - if ($token === $webform_submission->getToken()) { - $token = $new_submission->getToken(); - $url = Url::fromUserInput($form->getTargetUrl(), ['query' => ['os2forms-forloeb-ws-token' => $token]]); - $form = new RedirectResponse($url->toString()); - } - } - return $form; } From 8bca740af3b97ac8c28f342a9d89423301bc42ce Mon Sep 17 00:00:00 2001 From: Mikkel Ricky Date: Thu, 22 Sep 2022 13:53:05 +0200 Subject: [PATCH 03/14] Added retry task controller action --- os2forms_forloeb.routing.yml | 10 ++++++++ .../ForloebTaskConsoleController.php | 23 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/os2forms_forloeb.routing.yml b/os2forms_forloeb.routing.yml index 5754153..8304af4 100644 --- a/os2forms_forloeb.routing.yml +++ b/os2forms_forloeb.routing.yml @@ -7,3 +7,13 @@ os2forms_forloeb.forloeb_task_console_controller_execute: _permission: 'access content' options: no_cache: TRUE + +os2forms_forloeb.forloeb_task_console_controller_execute_retry: + path: 'os2forms-forloeb/execute-task-retry' + defaults: + _controller: '\Drupal\os2forms_forloeb\Controller\ForloebTaskConsoleController::retry' + _title: 'Task not yet ready' + requirements: + _permission: 'access content' + options: + no_cache: TRUE diff --git a/src/Controller/ForloebTaskConsoleController.php b/src/Controller/ForloebTaskConsoleController.php index 8f9d7b7..62beb7c 100644 --- a/src/Controller/ForloebTaskConsoleController.php +++ b/src/Controller/ForloebTaskConsoleController.php @@ -5,6 +5,7 @@ use Drupal\Component\Utility\UrlHelper; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Entity\EntityTypeManagerInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; use Drupal\maestro\Engine\MaestroEngine; use Drupal\maestro\Utility\TaskHandler; @@ -19,6 +20,8 @@ */ class ForloebTaskConsoleController extends ControllerBase { + use StringTranslationTrait; + /** * Update manager service. * @@ -82,6 +85,12 @@ public function execute() { $token = $this->requestStack->getCurrentRequest()->query->get('os2forms-forloeb-ws-token', ''); if ($token) { $queueRecord = $this->forloebTaskConsole->getQueueIdByWebformSubmissionToken($token); + if (empty($queueRecord)) { + return new RedirectResponse( + Url::fromRoute('os2forms_forloeb.forloeb_task_console_controller_execute_retry', + ['referrer' => \Drupal::request()->getRequestUri()])->toString() + ); + } } else { // For empty token there is user last task from taskconsole queue. @@ -150,4 +159,18 @@ public function execute() { return new RedirectResponse($redirect_to->toString()); } + /** + * Show message about task not yet ready. + * + * @return array + * The render array. + */ + public function retry() { + $referrer = $this->requestStack->getCurrentRequest()->query->get('referrer', '#'); + + return [ + '#markup' => $this->t('Your task is not yet ready. Please try again in 5 minutes.', [':referrer' => $referrer]), + ]; + } + } From e70e74020e620234bdd0d31bd45276a4a8b4991a Mon Sep 17 00:00:00 2001 From: Mikkel Ricky Date: Thu, 22 Sep 2022 15:39:26 +0200 Subject: [PATCH 04/14] DW-568: Renamed function --- src/Plugin/EngineTasks/MaestroWebformInheritTask.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Plugin/EngineTasks/MaestroWebformInheritTask.php b/src/Plugin/EngineTasks/MaestroWebformInheritTask.php index 703e0e9..e6516de 100644 --- a/src/Plugin/EngineTasks/MaestroWebformInheritTask.php +++ b/src/Plugin/EngineTasks/MaestroWebformInheritTask.php @@ -204,7 +204,7 @@ public static function webformElementAlter(array &$element, FormStateInterface $ * Get task values from session. */ private static function getTaskValues($queueID) { - $sessionKey = self::getTaskValuesSessionKey($queueID); + $sessionKey = self::formatTaskValuesSessionKey($queueID); return \Drupal::request()->getSession()->get($sessionKey); } @@ -212,14 +212,14 @@ private static function getTaskValues($queueID) { * Set task values in session. */ private static function setTaskValues($queueID, $values) { - $sessionKey = self::getTaskValuesSessionKey($queueID); + $sessionKey = self::formatTaskValuesSessionKey($queueID); \Drupal::request()->getSession()->set($sessionKey, $values); } /** - * Get task values session key. + * Format task values session key. */ - private static function getTaskValuesSessionKey(int $queueID) { + private static function formatTaskValuesSessionKey(int $queueID) { return sprintf('os2forms_forloeb_inherited_values_%s', $queueID); } From 2832a962a0afb4fad3fa06fe2fef21d0318a98bd Mon Sep 17 00:00:00 2001 From: Mikkel Ricky Date: Thu, 22 Sep 2022 15:41:00 +0200 Subject: [PATCH 05/14] DW-568: Added comments --- .../EngineTasks/MaestroWebformInheritTask.php | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/Plugin/EngineTasks/MaestroWebformInheritTask.php b/src/Plugin/EngineTasks/MaestroWebformInheritTask.php index e6516de..959584c 100644 --- a/src/Plugin/EngineTasks/MaestroWebformInheritTask.php +++ b/src/Plugin/EngineTasks/MaestroWebformInheritTask.php @@ -202,6 +202,12 @@ public static function webformElementAlter(array &$element, FormStateInterface $ /** * Get task values from session. + * + * @param int $queueID + * The queue ID. + * + * @return array + * The task values if any. */ private static function getTaskValues($queueID) { $sessionKey = self::formatTaskValuesSessionKey($queueID); @@ -210,16 +216,30 @@ private static function getTaskValues($queueID) { /** * Set task values in session. + * + * @param int $queueID + * The queue ID. + * @param array $values + * The values. + * + * @return array + * The task values if any. */ - private static function setTaskValues($queueID, $values) { + private static function setTaskValues($queueID, array $values) { $sessionKey = self::formatTaskValuesSessionKey($queueID); \Drupal::request()->getSession()->set($sessionKey, $values); } /** * Format task values session key. + * + * @param int $queueID + * The queue ID. + * + * @return string + * The formatted session key. */ - private static function formatTaskValuesSessionKey(int $queueID) { + private static function formatTaskValuesSessionKey($queueID) { return sprintf('os2forms_forloeb_inherited_values_%s', $queueID); } From 8908ec08fc79f2046f61ab387ac552e4d9f60609 Mon Sep 17 00:00:00 2001 From: Pernille Thorsen Date: Mon, 10 Oct 2022 14:55:27 +0200 Subject: [PATCH 06/14] Update CHANGELOG.md --- CHANGELOG.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c97a7c5..45666b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,13 +2,21 @@ All notable changes to this project should be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) -and this project adheres to [Semantic Versioning](http://semver.org/). +and this project adheres to [Semantic Versioning](5.0). See ["how do I make a good changelog record?"](https://keepachangelog.com/en/1.0.0/#how) before starting to add changes. ## [Unreleased] +## 2.5.0 - 11.10.2022 + +### Added +- retry task controller action +- Added support for inheriting values without creating a submission + +## 2.4.0 + ### Added - Github CI action for checking Drupal Coding standards with PHP Code Sniffer - Fixed coding standards issues From e5223697170c704d4296815ec000fce38105ecf6 Mon Sep 17 00:00:00 2001 From: Pernille Thorsen Date: Mon, 10 Oct 2022 15:06:02 +0200 Subject: [PATCH 07/14] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45666b7..8c07960 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All notable changes to this project should be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) -and this project adheres to [Semantic Versioning](5.0). +and this project adheres to [Semantic Versioning](http://semver.org/). See ["how do I make a good changelog record?"](https://keepachangelog.com/en/1.0.0/#how) before starting to add changes. From 0a2f3f98544cefae48528c6022a6e15e23bac5f8 Mon Sep 17 00:00:00 2001 From: Mikkel Ricky Date: Tue, 11 Oct 2022 10:06:28 +0200 Subject: [PATCH 08/14] Updated "allow-plugins" in composer.json --- composer.json | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 4c22192..5ae3ce8 100644 --- a/composer.json +++ b/composer.json @@ -100,6 +100,12 @@ ] }, "config": { - "sort-packages": true + "sort-packages": true, + "allow-plugins": { + "simplesamlphp/composer-module-installer": true, + "dealerdirect/phpcodesniffer-composer-installer": true, + "cweagans/composer-patches": true, + "zaporylie/composer-drupal-optimizations": true + } } } From 7b280b27fc0fd373e08ff40c22ba23ea8f7cb4ce Mon Sep 17 00:00:00 2001 From: Mikkel Ricky Date: Tue, 11 Oct 2022 10:06:37 +0200 Subject: [PATCH 09/14] Updated Git ignores --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 93aceb7..f50545c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ # Ignore IntelliJ -.idea/* \ No newline at end of file +.idea/* + +composer.lock +vendor From c85a5488113bd37715b7447f10bc661c7ca2d597 Mon Sep 17 00:00:00 2001 From: Mikkel Ricky Date: Tue, 11 Oct 2022 10:10:11 +0200 Subject: [PATCH 10/14] Applied coding standards --- os2forms_forloeb.module | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/os2forms_forloeb.module b/os2forms_forloeb.module index 3296639..7065819 100644 --- a/os2forms_forloeb.module +++ b/os2forms_forloeb.module @@ -96,7 +96,7 @@ function os2forms_forloeb_workflow_maestro_reassign_form_submit(&$form, &$form_s */ function os2forms_forloeb_maestro_batch_handlers() { return [ - 'end_notification_batch_function' => t('Batch function to send out flow completion notification to initiator.'), + '_os2forms_forloeb_end_notification_batch_function' => t('Batch function to send out flow completion notification to initiator.'), ]; } @@ -108,7 +108,7 @@ function os2forms_forloeb_maestro_batch_handlers() { * @param int $queueID * The Maestro queue ID. */ -function end_notification_batch_function($processID, $queueID) { +function _os2forms_forloeb_end_notification_batch_function($processID, $queueID) { /* * Pseudocode for handling this: From 9e86111d5c316bdcbdee332e3427a5e4b2f70040 Mon Sep 17 00:00:00 2001 From: Mikkel Ricky Date: Tue, 25 Oct 2022 12:55:04 +0200 Subject: [PATCH 11/14] DW-568: Fixed issue with form generation --- src/Plugin/EngineTasks/MaestroWebformInheritTask.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Plugin/EngineTasks/MaestroWebformInheritTask.php b/src/Plugin/EngineTasks/MaestroWebformInheritTask.php index 959584c..fcb6b05 100644 --- a/src/Plugin/EngineTasks/MaestroWebformInheritTask.php +++ b/src/Plugin/EngineTasks/MaestroWebformInheritTask.php @@ -133,7 +133,6 @@ public function getExecutableForm($modal, MaestroExecuteInteractive $parent) { $values['webform_id'] = $webformMachineName; $values['data'] = $field_values; - $form = parent::getExecutableForm($modal, $parent); $createSubmission = $task['data']['inherit_webform_create_submission'] ?? FALSE; if ($createSubmission) { @@ -162,6 +161,9 @@ public function getExecutableForm($modal, MaestroExecuteInteractive $parent) { $new_submission->bundle(), $taskUniqueSubmissionId, $sid ); + // Important: Apparently the form must be generated after calling + // MaestroEngine::createEntityIdentifier for this to work. + $form = parent::getExecutableForm($modal, $parent); // Catch os2forms-forloeb access token and pass it further. if ($form instanceof RedirectResponse && $token = \Drupal::request()->query->get('os2forms-forloeb-ws-token')) { // Check token to previous submission and update it to new one. @@ -179,6 +181,8 @@ public function getExecutableForm($modal, MaestroExecuteInteractive $parent) { $values['webformInheritID'] = $webformInheritID; self::setTaskValues($this->queueID, $values); + + $form = parent::getExecutableForm($modal, $parent); } return $form; From 37c95d19f70c594e09bb0054a77874e6f7fe0247 Mon Sep 17 00:00:00 2001 From: Mikkel Ricky Date: Tue, 25 Oct 2022 12:56:12 +0200 Subject: [PATCH 12/14] DW-568: Cleaned up --- src/Plugin/EngineTasks/MaestroWebformInheritTask.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Plugin/EngineTasks/MaestroWebformInheritTask.php b/src/Plugin/EngineTasks/MaestroWebformInheritTask.php index fcb6b05..392c89b 100644 --- a/src/Plugin/EngineTasks/MaestroWebformInheritTask.php +++ b/src/Plugin/EngineTasks/MaestroWebformInheritTask.php @@ -133,8 +133,7 @@ public function getExecutableForm($modal, MaestroExecuteInteractive $parent) { $values['webform_id'] = $webformMachineName; $values['data'] = $field_values; - - $createSubmission = $task['data']['inherit_webform_create_submission'] ?? FALSE; + $createSubmission = (bool) ($task['data']['inherit_webform_create_submission'] ?? FALSE); if ($createSubmission) { // Create submission. $new_submission = WebformSubmission::create($values); @@ -225,9 +224,6 @@ private static function getTaskValues($queueID) { * The queue ID. * @param array $values * The values. - * - * @return array - * The task values if any. */ private static function setTaskValues($queueID, array $values) { $sessionKey = self::formatTaskValuesSessionKey($queueID); From 380c53078cd2a8a010dca68b5ccad881aa57df2e Mon Sep 17 00:00:00 2001 From: Mikkel Ricky Date: Wed, 26 Oct 2022 17:38:36 +0200 Subject: [PATCH 13/14] DW-568: Used hook_webform_submission_prepare_form to set inherited values --- os2forms_forloeb.module | 9 ++++----- src/Plugin/EngineTasks/MaestroWebformInheritTask.php | 12 +++++++----- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/os2forms_forloeb.module b/os2forms_forloeb.module index d34fcf8..3b70f68 100644 --- a/os2forms_forloeb.module +++ b/os2forms_forloeb.module @@ -16,6 +16,7 @@ use Drupal\maestro\Engine\MaestroEngine; use Drupal\os2forms_forloeb\Plugin\EngineTasks\MaestroWebformInheritTask; use Drupal\webform\Entity\WebformSubmission; use Drupal\user\Entity\User; +use Drupal\webform\WebformSubmissionInterface; /** * Implements hook_maestro_interactive_handlers(). @@ -346,10 +347,8 @@ function os2forms_forloeb_maestro_post_fetch_assigned_queue_tasks($userID, &$que } /** - * Implements hook_webform_element_alter(). - * - * @see MaestroWebformInheritTask::webformElementAlter() + * Implements hook_ENTITY_TYPE_prepare_form(). */ -function os2forms_forloeb_webform_element_alter(array &$element, FormStateInterface $form_state, array $context) { - MaestroWebformInheritTask::webformElementAlter($element, $form_state, $context); +function os2forms_forloeb_webform_submission_prepare_form(WebformSubmissionInterface $webform_submission, string $operation, FormStateInterface $form_state) { + MaestroWebformInheritTask::webformSubmissionPrepareForm($webform_submission, $operation, $form_state); } diff --git a/src/Plugin/EngineTasks/MaestroWebformInheritTask.php b/src/Plugin/EngineTasks/MaestroWebformInheritTask.php index 392c89b..5d6642a 100644 --- a/src/Plugin/EngineTasks/MaestroWebformInheritTask.php +++ b/src/Plugin/EngineTasks/MaestroWebformInheritTask.php @@ -9,6 +9,7 @@ use Drupal\maestro\Form\MaestroExecuteInteractive; use Drupal\maestro\Engine\MaestroEngine; use Drupal\Core\Form\FormStateInterface; +use Drupal\webform\WebformSubmissionInterface; use Symfony\Component\HttpFoundation\RedirectResponse; /** @@ -188,17 +189,18 @@ public function getExecutableForm($modal, MaestroExecuteInteractive $parent) { } /** - * Implements hook_webform_element_alter(). + * Implements hook_ENTITY_TYPE_prepare_form(). */ - public static function webformElementAlter(array &$element, FormStateInterface $form_state, array $context) { + public static function webformSubmissionPrepareForm(WebformSubmissionInterface $webformSubmission, string $operation, FormStateInterface $formState): void { $request = \Drupal::request(); $isMaestro = (bool) $request->query->get('maestro', 0); $queueID = (int) $request->query->get('queueid', 0); if ($isMaestro && $queueID > 0) { $values = self::getTaskValues($queueID); - $elementId = $element['#webform_key']; - if (isset($values['data'][$elementId])) { - $element['#default_value'] = $values['data'][$elementId]; + if (isset($values['data'])) { + foreach ($values['data'] as $name => $value) { + $webformSubmission->setElementData($name, $value); + } } } } From 226285b932978414109ea27017f41e35ab83e9c1 Mon Sep 17 00:00:00 2001 From: Stanislav Kutasevits Date: Mon, 14 Nov 2022 12:03:12 +0200 Subject: [PATCH 14/14] Removing patch. Package not required by the project --- composer.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/composer.json b/composer.json index 4c22192..e2c8e9d 100644 --- a/composer.json +++ b/composer.json @@ -79,9 +79,6 @@ }, "drupal/coc_forms_auto_export": { "3240592 - Problem with phpseclib requirement in 2.x (https://www.drupal.org/project/coc_forms_auto_export/issues/3240592)": "https://www.drupal.org/files/issues/2021-10-04/requirement-namespace-3240592-1.patch" - }, - "drupal/smtp": { - "Duplicated attachments in emails generated by Webform: (https://www.drupal.org/project/smtp/issues/2995290)": "https://www.drupal.org/files/issues/2021-11-02/smtp-2995290-23.patch" } } },