Repository navigation
Allow configurating on which submission states handlers should run #333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
70fe8d3
48d8307
19d8e41
eeb2c86
f242e3a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,8 @@ class FasitWebformHandler extends WebformHandlerBase { | |
| public const FASIT_HANDLER_DOCUMENT_DESCRIPTION = 'document_description'; | ||
| public const FASIT_HANDLER_CPR_ELEMENT = 'cpr_element'; | ||
| public const FASIT_HANDLER_ATTACHMENT_ELEMENT = 'attachment_element'; | ||
| private const string ADDITIONAL = 'additional'; | ||
| private const string STATES = 'states'; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typed class constants require We either need to remove
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added php 8.3 requirement |
||
|
|
||
| /** | ||
| * The submission logger. | ||
|
|
@@ -79,6 +81,19 @@ public static function create(ContainerInterface $container, array $configuratio | |
| ); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| * | ||
| * @phpstan-return array<string, mixed> | ||
| */ | ||
| public function defaultConfiguration() { | ||
| return [ | ||
| self::ADDITIONAL => [ | ||
| self::STATES => [WebformSubmissionInterface::STATE_COMPLETED], | ||
| ], | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| * | ||
|
|
@@ -129,6 +144,30 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta | |
| '#size' => 5, | ||
| ]; | ||
|
|
||
| // Additional. | ||
| // Lifted from EmailWebformHandler::buildConfigurationForm(). | ||
| $resultsDisabled = (bool) $this->getWebform()->getSetting('results_disabled'); | ||
| $form[self::ADDITIONAL] = [ | ||
| '#type' => 'fieldset', | ||
| '#title' => $this->t('Additional settings'), | ||
| ]; | ||
| // Settings: States. | ||
| $states = (array) ($this->configuration[self::ADDITIONAL][self::STATES] ?? NULL); | ||
| $form[self::ADDITIONAL][self::STATES] = [ | ||
| '#type' => 'checkboxes', | ||
| '#title' => $this->t('Run handler when …'), | ||
| '#options' => [ | ||
| WebformSubmissionInterface::STATE_DRAFT_CREATED => $this->t('<b>draft is created</b>.'), | ||
| WebformSubmissionInterface::STATE_DRAFT_UPDATED => $this->t('<b>draft is updated</b>.'), | ||
| WebformSubmissionInterface::STATE_CONVERTED => $this->t('anonymous <b>submission is converted</b> to authenticated.'), | ||
| WebformSubmissionInterface::STATE_COMPLETED => $this->t('<b>submission is completed</b>.'), | ||
| WebformSubmissionInterface::STATE_UPDATED => $this->t('<b>submission is updated</b>.'), | ||
| WebformSubmissionInterface::STATE_LOCKED => $this->t('<b>submission is locked</b>.'), | ||
| ], | ||
| '#access' => !$resultsDisabled, | ||
| '#default_value' => $resultsDisabled ? [WebformSubmissionInterface::STATE_COMPLETED] : $states, | ||
| ]; | ||
|
|
||
| return $this->setSettingsParents($form); | ||
| } | ||
|
|
||
|
|
@@ -143,12 +182,23 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s | |
| $this->configuration[self::FASIT_HANDLER_GENERAL][self::FASIT_HANDLER_DOCUMENT_DESCRIPTION] = $form_state->getValue(self::FASIT_HANDLER_GENERAL)[self::FASIT_HANDLER_DOCUMENT_DESCRIPTION]; | ||
| $this->configuration[self::FASIT_HANDLER_GENERAL][self::FASIT_HANDLER_CPR_ELEMENT] = $form_state->getValue(self::FASIT_HANDLER_GENERAL)[self::FASIT_HANDLER_CPR_ELEMENT]; | ||
| $this->configuration[self::FASIT_HANDLER_GENERAL][self::FASIT_HANDLER_ATTACHMENT_ELEMENT] = $form_state->getValue(self::FASIT_HANDLER_GENERAL)[self::FASIT_HANDLER_ATTACHMENT_ELEMENT]; | ||
|
|
||
| $additional = $form_state->getValue(self::ADDITIONAL); | ||
| // Clean up states. | ||
| $additional[self::STATES] = array_values(array_filter($additional[self::STATES])); | ||
| $this->configuration[self::ADDITIONAL] = $additional; | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public function postSave(WebformSubmissionInterface $webform_submission, $update = TRUE): void { | ||
| $submissionState = $webform_submission->getWebform()->getSetting('results_disabled') ? WebformSubmissionInterface::STATE_COMPLETED : $webform_submission->getState(); | ||
| $enabledStates = (array) ($this->configuration[self::ADDITIONAL][self::STATES] ?? NULL); | ||
| if (!in_array($submissionState, $enabledStates)) { | ||
| return; | ||
| } | ||
|
|
||
| $queueStorage = $this->entityTypeManager->getStorage('advancedqueue_queue'); | ||
| /** @var \Drupal\advancedqueue\Entity\Queue $queue */ | ||
| $queue = $queueStorage->load('fasit_queue'); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @file | ||
| * Install hooks for os2forms_fbs_handler. | ||
| */ | ||
|
|
||
| use Drupal\webform\WebformSubmissionInterface; | ||
|
|
||
| /** | ||
| * Set states config to completed on existing fbs handlers. | ||
| */ | ||
| function os2forms_fbs_handler_update_10001(): void { | ||
| // To avoid having to load full webforms we load and update webform configs. | ||
| $configFactory = \Drupal::configFactory(); | ||
|
|
||
| foreach ($configFactory->listAll('webform.webform.') as $name) { | ||
| $config = $configFactory->getEditable($name); | ||
| $handlers = $config->get('handlers'); | ||
| if (!is_array($handlers)) { | ||
| continue; | ||
| } | ||
|
|
||
| $changed = FALSE; | ||
|
|
||
| foreach ($handlers as $handlerKey => $handler) { | ||
| // $handler['id'] is the handler plugin id. | ||
| if (($handler['id'] ?? NULL) !== 'os2forms_fbs') { | ||
| continue; | ||
| } | ||
| $handlers[$handlerKey]['settings']['additional']['states'] = [WebformSubmissionInterface::STATE_COMPLETED]; | ||
| $changed = TRUE; | ||
| } | ||
|
|
||
| if ($changed) { | ||
| $config->set('handlers', $handlers)->save(); | ||
| } | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.