diff --git a/docroot/modules/custom/foia_webform/foia_webform.module b/docroot/modules/custom/foia_webform/foia_webform.module index bbd2bbfa9..35ec406e8 100644 --- a/docroot/modules/custom/foia_webform/foia_webform.module +++ b/docroot/modules/custom/foia_webform/foia_webform.module @@ -8,18 +8,16 @@ use Drupal\webform\WebformInterface; /** - * Programmatically add the foia_email handler to new webforms. + * Programmatically add the foia_submission_queue handler to new webforms. */ function foia_webform_webform_insert(WebformInterface $webform) { $webform_handler_manager = \Drupal::service('plugin.manager.webform.handler'); - $webform_handler = $webform_handler_manager->createInstance('foia_email'); + $webform_handler = $webform_handler_manager->createInstance('foia_submission_queue'); - // @todo: Add Submission Email if we add Agency Component entity reference. - // Set default configuration. $webform_handler->setConfiguration([ - 'id' => 'foia_email', - 'label' => 'FOIA Email', - 'handler_id' => 'foia_email', + 'id' => 'foia_submission_queue', + 'label' => 'FOIA Submission Queue', + 'handler_id' => 'foia_submission_queue', 'status' => TRUE, 'weight' => 0, 'settings' => [ diff --git a/docroot/modules/custom/foia_webform/src/Plugin/QueueWorker/FoiaSubmissionQueueWorker.php b/docroot/modules/custom/foia_webform/src/Plugin/QueueWorker/FoiaSubmissionQueueWorker.php new file mode 100644 index 000000000..f82703c15 --- /dev/null +++ b/docroot/modules/custom/foia_webform/src/Plugin/QueueWorker/FoiaSubmissionQueueWorker.php @@ -0,0 +1,47 @@ +webformStorage = $webformStorage; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $container->get('entity.manager')->getStorage('webform_submission') + ); + } + + /** + * {@inheritdoc} + */ + public function processItem($data) {} + +} diff --git a/docroot/modules/custom/foia_webform/src/Plugin/WebformHandler/FoiaSubmissionQueueHandler.php b/docroot/modules/custom/foia_webform/src/Plugin/WebformHandler/FoiaSubmissionQueueHandler.php new file mode 100644 index 000000000..1e7e6d6f6 --- /dev/null +++ b/docroot/modules/custom/foia_webform/src/Plugin/WebformHandler/FoiaSubmissionQueueHandler.php @@ -0,0 +1,65 @@ +getWebform()->getSetting('results_disabled') ? WebformSubmissionInterface::STATE_COMPLETED : $webform_submission->getState(); + if (in_array($state, $this->configuration['states'])) { + // Get the Webform generated email message. + $message = $this->getMessage($webform_submission); + // Add the submission to the queue. + $this->queueSubmission($webform_submission, $message); + } + } + + /** + * Adds the submission to the foia_submissions queue. + * + * @param \Drupal\webform\WebformSubmissionInterface $webform_submission + * The webform submission object. + * @param array $message + * The email message array. + */ + private function queueSubmission(WebformSubmissionInterface $webform_submission, array $message) { + // @var QueueFactory $queue_factory + $queue_factory = \Drupal::service('queue'); + + // @var QueueInterface $queue + $foia_submission_queue = $queue_factory->get('foia_submissions'); + $submission = new \stdClass(); + $submission->sid = $webform_submission->id(); + $submission->message = $message; + + // Log the form submission. + \Drupal::logger('foia_webform') + ->info('FOIA form submission #%sid added to queue.', + [ + '%sid' => $webform_submission->id(), + 'link' => $webform_submission->toLink($this->t('View'))->toString(), + ] + ); + + $foia_submission_queue->createItem($submission); + } + +}