diff --git a/modules/localgov_workflows_notifications/src/Form/LocalgovWorkflowsNotificationsSettingsForm.php b/modules/localgov_workflows_notifications/src/Form/LocalgovWorkflowsNotificationsSettingsForm.php index 49ab929..55ef6c0 100644 --- a/modules/localgov_workflows_notifications/src/Form/LocalgovWorkflowsNotificationsSettingsForm.php +++ b/modules/localgov_workflows_notifications/src/Form/LocalgovWorkflowsNotificationsSettingsForm.php @@ -79,6 +79,23 @@ public function buildForm(array $form, FormStateInterface $form_state): array { '#default_value' => $this->config('localgov_workflows_notifications.settings')->get('email_frequency') ?? 1, ]; + $form['test_options'] = [ + '#type' => 'details', + '#title' => $this->t('Testing options'), + '#open' => FALSE, + ]; + $form['test_options']['reset_help'] = [ + '#type' => 'item', + '#markup' => $this->t('

Last run time: @time

Resetting the last run time will force notifications to be sent for all content needing review. This is useful when testing email notifications.

', [ + '@time' => $this->timer->getLastRun() ? date('F j Y, g:ia', $this->timer->getLastRun()) : $this->t('Never'), + ]), + ]; + $form['test_options']['reset_last_run'] = [ + '#type' => 'submit', + '#value' => $this->t('Rest last run time'), + '#submit' => ['::resetLastRun'], + ]; + return parent::buildForm($form, $form_state); } @@ -102,4 +119,11 @@ public function submitForm(array &$form, FormStateInterface $form_state): void { parent::submitForm($form, $form_state); } + /** + * Reset last run time submit handler. + */ + public function resetLastRun(array &$form, FormStateInterface $form_state): void { + $this->timer->reset(); + } + } diff --git a/modules/localgov_workflows_notifications/src/NotificationTimer.php b/modules/localgov_workflows_notifications/src/NotificationTimer.php index 1a72379..628466c 100644 --- a/modules/localgov_workflows_notifications/src/NotificationTimer.php +++ b/modules/localgov_workflows_notifications/src/NotificationTimer.php @@ -49,6 +49,13 @@ public function getLastRun(): ?int { return $this->state->get(self::LAST_RUN); } + /** + * {@inheritdoc} + */ + public function reset(): void { + $this->state->set(self::LAST_RUN, 0); + } + /** * {@inheritdoc} */ diff --git a/modules/localgov_workflows_notifications/src/NotificationTimerInterface.php b/modules/localgov_workflows_notifications/src/NotificationTimerInterface.php index d7de6f9..44d9b29 100644 --- a/modules/localgov_workflows_notifications/src/NotificationTimerInterface.php +++ b/modules/localgov_workflows_notifications/src/NotificationTimerInterface.php @@ -22,6 +22,11 @@ interface NotificationTimerInterface { */ public function getLastRun(): ?int; + /** + * Reset the notification timer. + */ + public function reset(): void; + /** * Update the notification timer. */