@@ -37,6 +37,8 @@ final class WebformHandlerSF2900 extends WebformHandlerBase {
3737 public const string ID = 'os2forms_fordelingskomponent_sf2900 ' ;
3838
3939 public const string SECTION_SF2900 = 'sf2900 ' ;
40+ private const string ADDITIONAL = 'additional ' ;
41+ private const string STATES = 'states ' ;
4042
4143 /**
4244 * The settings.
@@ -90,6 +92,31 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
9092 '#tree ' => TRUE ,
9193 ] + $ this ->buildConfigurationFormDistributionObject ();
9294
95+ // Additional.
96+ // Lifted from EmailWebformHandler::buildConfigurationForm().
97+ $ resultsDisabled = (bool ) $ this ->getWebform ()->getSetting ('results_disabled ' );
98+ $ form [self ::ADDITIONAL ] = [
99+ '#type ' => 'fieldset ' ,
100+ '#title ' => $ this ->t ('Additional settings ' ),
101+ ];
102+ // Settings: States.
103+ $ states = (array ) ($ this ->configuration [self ::ADDITIONAL ][self ::STATES ] ?? NULL );
104+ $ form [self ::ADDITIONAL ][self ::STATES ] = [
105+ '#type ' => 'checkboxes ' ,
106+ '#title ' => $ this ->t ('Send distribution object when … ' ),
107+ '#options ' => [
108+ WebformSubmissionInterface::STATE_DRAFT_CREATED => $ this ->t ('<b>draft is created</b>. ' ),
109+ WebformSubmissionInterface::STATE_DRAFT_UPDATED => $ this ->t ('<b>draft is updated</b>. ' ),
110+ WebformSubmissionInterface::STATE_CONVERTED => $ this ->t ('anonymous <b>submission is converted</b> to authenticated. ' ),
111+ WebformSubmissionInterface::STATE_COMPLETED => $ this ->t ('<b>submission is completed</b>. ' ),
112+ WebformSubmissionInterface::STATE_UPDATED => $ this ->t ('<b>submission is updated</b>. ' ),
113+ WebformSubmissionInterface::STATE_DELETED => $ this ->t ('<b>submission is deleted</b>. ' ),
114+ WebformSubmissionInterface::STATE_LOCKED => $ this ->t ('<b>submission is locked</b>. ' ),
115+ ],
116+ '#access ' => !$ resultsDisabled ,
117+ '#default_value ' => $ resultsDisabled ? [WebformSubmissionInterface::STATE_COMPLETED ] : $ states ,
118+ ];
119+
93120 return parent ::buildConfigurationForm ($ form , $ form_state );
94121 }
95122
@@ -412,15 +439,20 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s
412439 ] as $ name ) {
413440 $ this ->configuration [$ name ] = $ form_state ->getValue ($ name );
414441 }
442+
443+ $ additional = $ form_state ->getValue (self ::ADDITIONAL );
444+ // Clean up states.
445+ $ additional [self ::STATES ] = array_values (array_filter ($ additional [self ::STATES ]));
446+ $ this ->configuration [self ::ADDITIONAL ] = $ additional ;
415447 }
416448
417449 /**
418450 * {@inheritdoc}
419451 */
420452 public function postSave (WebformSubmissionInterface $ webform_submission , $ update = TRUE ) {
421- // Run only when submission is completed.
422- // @todo Run on update?
423- if (!$ webform_submission -> isCompleted ( )) {
453+ $ submissionState = $ webform_submission -> getWebform ()-> getSetting ( ' results_disabled ' ) ? WebformSubmissionInterface:: STATE_COMPLETED : $ webform_submission -> getState ();
454+ $ enabledStates = ( array ) ( $ this -> configuration [ self :: ADDITIONAL ][ self :: STATES ] ?? NULL );
455+ if (!in_array ( $ submissionState , $ enabledStates )) {
424456 return ;
425457 }
426458
@@ -451,17 +483,36 @@ public function postPurge(array $webform_submissions) {
451483 #[\Override]
452484 public function getSummary () {
453485 $ settings = $ this ->settingsService ->getHandlerSettings ($ this );
486+ $ enabledStates = array_filter ((array ) $ this ->getSetting (self ::ADDITIONAL )[self ::STATES ] ?? []);
487+
488+ // Set state.
489+ $ states = [
490+ WebformSubmissionInterface::STATE_DRAFT_CREATED => $ this ->t ('Draft created ' ),
491+ WebformSubmissionInterface::STATE_DRAFT_UPDATED => $ this ->t ('Draft updated ' ),
492+ WebformSubmissionInterface::STATE_CONVERTED => $ this ->t ('Converted ' ),
493+ WebformSubmissionInterface::STATE_COMPLETED => $ this ->t ('Completed ' ),
494+ WebformSubmissionInterface::STATE_UPDATED => $ this ->t ('Updated ' ),
495+ WebformSubmissionInterface::STATE_DELETED => $ this ->t ('Deleted ' ),
496+ ];
497+ $ enabledStates = array_intersect_key ($ states , array_combine ($ enabledStates , $ enabledStates ));
498+
499+ $ build [self ::STATES ] = [
500+ '#prefix ' => '<div> ' ,
501+ '#suffix ' => '</div> ' ,
502+ '#markup ' => $ this ->t ('Send @type distribution object when @states ' , [
503+ '@type ' => $ settings ->distributionObject ->distributionType ,
504+ '@states ' => implode (', ' , $ enabledStates ),
505+ ]),
506+ ];
454507
455- $ build = [
456- 'info ' => [
457- '#prefix ' => '<div> ' ,
458- '#suffix ' => '</div> ' ,
459- '#markup ' => $ this ->t ('KLE-emne: %kle_emne; Handling-facet: %handling_facet ' ,
460- [
461- '%kle_emne ' => $ settings ->distributionContext ->kleEmne ,
462- '%handling_facet ' => $ settings ->distributionContext ->handlingFacet ,
463- ]),
464- ],
508+ $ build ['info ' ] = [
509+ '#prefix ' => '<div> ' ,
510+ '#suffix ' => '</div> ' ,
511+ '#markup ' => $ this ->t ('KLE-emne: %kle_emne; Handling-facet: %handling_facet ' ,
512+ [
513+ '%kle_emne ' => $ settings ->distributionContext ->kleEmne ,
514+ '%handling_facet ' => $ settings ->distributionContext ->handlingFacet ,
515+ ]),
465516 ];
466517
467518 $ items = [];
@@ -503,6 +554,17 @@ public function getSummary() {
503554 return $ build ;
504555 }
505556
557+ /**
558+ * {@inheritdoc}
559+ */
560+ public function defaultConfiguration (): array {
561+ return [
562+ self ::ADDITIONAL => [
563+ self ::STATES => [WebformSubmissionInterface::STATE_COMPLETED ],
564+ ],
565+ ];
566+ }
567+
506568 /**
507569 * Get attachment elements.
508570 *
0 commit comments