diff --git a/os2forms_forloeb.module b/os2forms_forloeb.module index f3db24a..274893c 100644 --- a/os2forms_forloeb.module +++ b/os2forms_forloeb.module @@ -97,3 +97,52 @@ 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) { + + /* + * 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 = $webform_submission->getWebform(); + $handlers = $webform->getHandlers(); + + foreach ($handlers as $handler) { + if (method_exists($handler, 'getMessage')) { + $message = $handler->getMessage($webform_submission); + $handler->sendMessage($webform_submission, $message); + } + } + } + + return TRUE; +}