From 5de3bbf537d51b80880e5fe1bbe99c9a46677edc Mon Sep 17 00:00:00 2001 From: Carsten Agger Date: Tue, 27 Apr 2021 11:31:51 +0200 Subject: [PATCH 1/4] Added batch function skeleton. --- os2forms_forloeb.module | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/os2forms_forloeb.module b/os2forms_forloeb.module index f3db24a..bd0568d 100644 --- a/os2forms_forloeb.module +++ b/os2forms_forloeb.module @@ -97,3 +97,27 @@ function os2forms_forloeb_workflow_maestro_reassign_form_submit(&$form, &$form_s drupal_set_message("Content Reassigned"); } + +/** + * * Implements hook_maestro_batch_handlers(). + * * + * * Array of function names and help text that will be displayed + * * in the edit task form under the handler field. + * */ +function os2forms_forloeb_maestro_batch_handlers() { + return [ + 'end_notification_batch_function' => t('Batch function to send out flow completion notification to initiator.'), + ]; +} + +/** + * * @param int $processID + * * The Maestro process ID. + * * @param int $queueID + * * The Maestro queue ID. + * */ +function end_notification_batch_function($processID, $queueID) { + + + return TRUE; +} From 519d74b7ec1882035fefa6d42ec9e7d1f15f92b0 Mon Sep 17 00:00:00 2001 From: Carsten Agger Date: Wed, 28 Apr 2021 12:11:42 +0200 Subject: [PATCH 2/4] Start coding this. --- os2forms_forloeb.module | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/os2forms_forloeb.module b/os2forms_forloeb.module index bd0568d..a315b4a 100644 --- a/os2forms_forloeb.module +++ b/os2forms_forloeb.module @@ -118,6 +118,23 @@ function os2forms_forloeb_maestro_batch_handlers() { * */ function end_notification_batch_function($processID, $queueID) { - - return TRUE; + /* + * Pseudocode for handling this: + * + * * Get entity item for webform which spawned this process + * (ID "submission"). + * foreach handler in webform: { + * if (email_handler) { + * email_handler.submit(); + * } + * } + */ + $sid = MaestroEngine::getEntityIdentiferByUniqueID($processID, 'submission'); + + if ($sid) { + $webform_submission = \Drupal\webform\Entity\WebformSubmission::load($sid); + $webform = + } + + return TRUE; } From b7194f6298e7d8dc6c3612bd02e33246ea0724e8 Mon Sep 17 00:00:00 2001 From: Carsten Agger Date: Wed, 28 Apr 2021 15:20:40 +0200 Subject: [PATCH 3/4] Added a few log statements, ready to test. --- os2forms_forloeb.module | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/os2forms_forloeb.module b/os2forms_forloeb.module index a315b4a..95e78a1 100644 --- a/os2forms_forloeb.module +++ b/os2forms_forloeb.module @@ -131,9 +131,20 @@ function end_notification_batch_function($processID, $queueID) { */ $sid = MaestroEngine::getEntityIdentiferByUniqueID($processID, 'submission'); + \Drupal::logger('os2forms_forloeb')->notice("Hello!"); + \Drupal::logger('os2forms_forloeb')->notice($sid); if ($sid) { $webform_submission = \Drupal\webform\Entity\WebformSubmission::load($sid); - $webform = + $webform = $webform_submission->getWebform(); + $handlers = $webform->getHandlers(); + + foreach ($handler as $handler) { + $is_email_handler = ($handler instanceof EmailWebformHandler); + if ($is_email_handler) { + $message = $handler->getMessage($webform_submission); + $handler->sendMessage($webform_submission, $message); + } + } } return TRUE; From 8f109826685093f9b6f3a73f5a369159bb66b3f9 Mon Sep 17 00:00:00 2001 From: Carsten Agger Date: Thu, 29 Apr 2021 14:58:35 +0200 Subject: [PATCH 4/4] Send message from all email handlers when maestro process is done. --- os2forms_forloeb.module | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/os2forms_forloeb.module b/os2forms_forloeb.module index 95e78a1..274893c 100644 --- a/os2forms_forloeb.module +++ b/os2forms_forloeb.module @@ -131,16 +131,13 @@ function end_notification_batch_function($processID, $queueID) { */ $sid = MaestroEngine::getEntityIdentiferByUniqueID($processID, 'submission'); - \Drupal::logger('os2forms_forloeb')->notice("Hello!"); - \Drupal::logger('os2forms_forloeb')->notice($sid); if ($sid) { $webform_submission = \Drupal\webform\Entity\WebformSubmission::load($sid); $webform = $webform_submission->getWebform(); $handlers = $webform->getHandlers(); - foreach ($handler as $handler) { - $is_email_handler = ($handler instanceof EmailWebformHandler); - if ($is_email_handler) { + foreach ($handlers as $handler) { + if (method_exists($handler, 'getMessage')) { $message = $handler->getMessage($webform_submission); $handler->sendMessage($webform_submission, $message); }