Skip to content

Commit 7363ead

Browse files
committed
Added changes from pr 187
1 parent 6394396 commit 7363ead

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ before starting to add changes. Use example [placed in the end of the page](#exa
1919
- Added condition to maestro notification submission handler
2020
- [PR-192](https://github.com/OS2Forms/os2forms/pull/192)
2121
- Fix bug in MitidChildrenSelectAjaxBehaviour.php
22+
- [PR-187](https://github.com/OS2Forms/os2forms/pull/187)
23+
- Avoid double-saving submissions when handling name and address protection.
2224

2325
## Patch release selvbetjening 4.6.0
2426

modules/os2forms_nemid/os2forms_nemid.module

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,5 +469,4 @@ function os2forms_nemid_submission_set_address_protected(array $form, FormStateI
469469
$data = $webformSubmission->getData();
470470
$data['os2forms_nemid_elements_nemid_address_protected'] = TRUE;
471471
$webformSubmission->setData($data);
472-
$webformSubmission->save();
473472
}

modules/os2forms_nemid/src/Plugin/WebformElement/NemidAddress.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,18 @@ public function alterForm(array &$element, array &$form, FormStateInterface $for
4747
// Only manipulate element on submission create form.
4848
if (!$webformSubmission->isCompleted()) {
4949
if ($cprLookupResult && $cprLookupResult->isNameAddressProtected()) {
50-
$element['#info_message'] = 'adresse beskyttelse';
5150
NestedArray::setValue($form['elements'], $element['#webform_parents'], $element);
52-
$form['actions']['submit']['#submit'][] = 'os2forms_nemid_submission_set_address_protected';
51+
52+
// It is important the 'os2forms_nemid_submission_set_address_protected'
53+
// submit action is executed before the 'save' action. Otherwise,
54+
// submissions are both created and completed, resulting in unexpected
55+
// behavior, e.g. handlers being run twice.
56+
if (isset($form['actions']['submit']['#submit']) && is_array($form['actions']['submit']['#submit'])) {
57+
array_unshift($form['actions']['submit']['#submit'], 'os2forms_nemid_submission_set_address_protected');
58+
}
59+
else {
60+
$form['actions']['submit']['#submit'][] = 'os2forms_nemid_submission_set_address_protected';
61+
}
5362
}
5463
}
5564
else {

0 commit comments

Comments
 (0)