Skip to content

Commit ba54de8

Browse files
authored
Merge pull request #79 from OS2Forms/develop
Deploy 3.13.3
2 parents a7ad8f1 + 664589b commit ba54de8

File tree

8 files changed

+128
-30
lines changed

8 files changed

+128
-30
lines changed

CHANGELOG.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ before starting to add changes. Use example [placed in the end of the page](#exa
1111

1212
## [Unreleased]
1313

14+
## [3.13.3] 2023-12-05
15+
16+
- [#76](https://github.com/OS2Forms/os2forms/pull/76)
17+
Fixed digital post logging on submissions.
18+
- [#74](https://github.com/OS2Forms/os2forms/pull/74)
19+
Allow composite elements in Maestro notification recipient
20+
- [#73](https://github.com/OS2Forms/os2forms/pull/73a)
21+
Fix issue with nested elements in webform inherit
22+
- [#77](https://github.com/OS2Forms/os2forms/pull/77)
23+
Fix color picker fields in os2forms_webform_maps
24+
1425
## [3.13.2] 2023-10-19
1526

1627
- Fixing CPR fetch pattern
@@ -179,7 +190,28 @@ before starting to add changes. Use example [placed in the end of the page](#exa
179190
- Security in case of vulnerabilities.
180191
```
181192

182-
[Unreleased]: https://github.com/OS2Forms/os2forms/compare/3.5.0...HEAD
183-
[3.5.0]: https://github.com/OS2Forms/os2forms/compare/3.2.5...3.5.0
193+
[Unreleased]: https://github.com/OS2Forms/os2forms/compare/3.13.3...HEAD
194+
[3.13.3]: https://github.com/OS2Forms/os2forms/compare/3.13.2...3.13.3
195+
[3.13.2]: https://github.com/OS2Forms/os2forms/compare/3.13.1...3.13.2
196+
[3.13.1]: https://github.com/OS2Forms/os2forms/compare/3.13.0...3.13.1
197+
[3.13.0]: https://github.com/OS2Forms/os2forms/compare/3.12.2...3.13.0
198+
[3.12.2]: https://github.com/OS2Forms/os2forms/compare/3.12.1...3.12.2
199+
[3.12.1]: https://github.com/OS2Forms/os2forms/compare/3.12.0...3.12.1
200+
[3.12.0]: https://github.com/OS2Forms/os2forms/compare/3.11.0...3.12.0
201+
[3.11.0]: https://github.com/OS2Forms/os2forms/compare/3.10.0...3.11.0
202+
[3.10.0]: https://github.com/OS2Forms/os2forms/compare/3.9.0...3.10.0
203+
[3.9.0]: https://github.com/OS2Forms/os2forms/compare/3.8.3...3.9.0
204+
[3.8.3]: https://github.com/OS2Forms/os2forms/compare/3.8.2...3.8.3
205+
[3.8.2]: https://github.com/OS2Forms/os2forms/compare/3.8.1...3.8.2
206+
[3.8.1]: https://github.com/OS2Forms/os2forms/compare/3.8.0...3.8.1
207+
[3.8.0]: https://github.com/OS2Forms/os2forms/compare/3.7.0...3.8.0
208+
[3.7.0]: https://github.com/OS2Forms/os2forms/compare/3.6.0...3.7.0
209+
[3.6.0]: https://github.com/OS2Forms/os2forms/compare/3.5.0...3.6.0
210+
[3.5.0]: https://github.com/OS2Forms/os2forms/compare/3.4.0...3.5.0
211+
[3.4.0]: https://github.com/OS2Forms/os2forms/compare/3.3.0...3.4.0
212+
[3.3.0]: https://github.com/OS2Forms/os2forms/compare/3.2.9...3.3.0
213+
[3.2.9]: https://github.com/OS2Forms/os2forms/compare/3.2.8...3.2.9
214+
[3.2.8]: https://github.com/OS2Forms/os2forms/compare/3.2.7...3.2.8
215+
[3.2.7]: https://github.com/OS2Forms/os2forms/compare/3.2.6...3.2.7
184216
[3.2.6]: https://github.com/OS2Forms/os2forms/compare/3.2.5...3.2.6
185217
[3.2.5]: https://github.com/OS2Forms/os2forms/compare/3.2.4...3.2.5

modules/os2forms_digital_post/os2forms_digital_post.services.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ services:
55

66
logger.channel.os2forms_digital_post_submission:
77
parent: logger.channel_base
8-
arguments: [ 'os2forms_digital_post_submission' ]
8+
arguments: [ 'webform_submission' ]
99

1010
Drupal\os2forms_digital_post\Helper\Settings:
1111
arguments:

modules/os2forms_digital_post/src/Helper/WebformHelperSF1601.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ public function log($level, $message, array $context = []): void {
217217
*/
218218
public function createJob(WebformSubmissionInterface $webformSubmission, array $handlerConfiguration): ?Job {
219219
$context = [
220+
'handler_id' => 'os2forms_digital_post',
220221
'webform_submission' => $webformSubmission,
221222
];
222223

@@ -230,15 +231,13 @@ public function createJob(WebformSubmissionInterface $webformSubmission, array $
230231
$queue->enqueueJob($job);
231232
$context['@queue'] = $queue->id();
232233
$this->notice('Job for sending digital post add to the queue @queue.', $context + [
233-
'handler_id' => 'os2forms_digital_post',
234234
'operation' => 'digital post queued for sending',
235235
]);
236236

237237
return $job;
238238
}
239239
catch (\Exception $exception) {
240240
$this->error('Error creating job for sending digital post.', $context + [
241-
'handler_id' => 'os2forms_digital_post',
242241
'operation' => 'digital post failed',
243242
]);
244243
return NULL;
@@ -253,6 +252,10 @@ public function createJob(WebformSubmissionInterface $webformSubmission, array $
253252
public function processJob(Job $job): JobResult {
254253
$payload = $job->getPayload();
255254

255+
$context = [
256+
'handler_id' => 'os2forms_digital_post',
257+
'operation' => 'digital post send',
258+
];
256259
try {
257260
$submissionId = $payload['submissionId'];
258261
$submission = $this->loadSubmission($submissionId);
@@ -267,21 +270,16 @@ public function processJob(Job $job): JobResult {
267270
$message));
268271
}
269272

273+
$context['webform_submission'] = $submission;
270274
$this->sendDigitalPost($submission, $payload['handlerConfiguration']);
271275

272-
$this->notice('Digital post sent', [
273-
'handler_id' => 'os2forms_digital_post',
274-
'operation' => 'digital post send',
275-
'webform_submission' => $submission,
276-
]);
276+
$this->notice('Digital post sent', $context);
277277

278278
return JobResult::success();
279279
}
280280
catch (\Exception $e) {
281-
$this->error('Error: @message', [
281+
$this->error('Error: @message', $context + [
282282
'@message' => $e->getMessage(),
283-
'handler_id' => 'os2forms_digital_post',
284-
'operation' => 'digital post send',
285283
]);
286284

287285
return JobResult::failure($e->getMessage());

modules/os2forms_forloeb/src/MaestroHelper.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Drupal\advancedqueue\Job;
99
use Drupal\advancedqueue\JobResult;
1010
use Drupal\Component\Render\MarkupInterface;
11+
use Drupal\Component\Utility\NestedArray;
1112
use Drupal\Core\Config\ConfigFactoryInterface;
1213
use Drupal\Core\Config\ImmutableConfig;
1314
use Drupal\Core\Entity\EntityStorageInterface;
@@ -466,6 +467,17 @@ public function renderNotification(WebformSubmissionInterface $submission, strin
466467
?? $data[$recipientElement]
467468
?? NULL;
468469

470+
// Handle composite elements.
471+
if ($recipient === NULL) {
472+
// Composite subelement keys consist of
473+
// the composite element key and the subelement key separated by '__',
474+
// e.g. 'contact__name'.
475+
if (str_contains($recipientElement, '__')) {
476+
$keys = explode('__', $recipientElement);
477+
$recipient = NestedArray::getValue($data, $keys);
478+
}
479+
}
480+
469481
if ($notificationType === self::NOTIFICATION_ESCALATION) {
470482
$recipient = $settings[MaestroNotificationHandler::NOTIFICATION][$notificationType][MaestroNotificationHandler::NOTIFICATION_RECIPIENT] ?? NULL;
471483
}

modules/os2forms_forloeb/src/Plugin/EngineTasks/MaestroWebformInheritTask.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
namespace Drupal\os2forms_forloeb\Plugin\EngineTasks;
44

5+
use Drupal\Component\Utility\NestedArray;
56
use Drupal\Core\Form\FormStateInterface;
67
use Drupal\maestro\Engine\MaestroEngine;
78
use Drupal\maestro_webform\Plugin\EngineTasks\MaestroWebformTask;
9+
use Drupal\webform\Entity\Webform;
810
use Drupal\webform\Entity\WebformSubmission;
911
use Drupal\webform\Utility\WebformArrayHelper;
1012

@@ -152,9 +154,18 @@ public static function webformSubmissionFormAlter(array &$form, FormStateInterfa
152154
if ('webform_submission' === ($entityIdentifier['entity_type'] ?? NULL)) {
153155
$submission = WebformSubmission::load($entityIdentifier['entity_id']);
154156
$data = $submission->getData();
155-
foreach ($data as $key => $value) {
156-
if (isset($form['elements'][$key])) {
157-
$form['elements'][$key]['#default_value'] = $value;
157+
158+
// The target element may be hidden inside sections or field groups
159+
// on the target form. Therefore, we need to load that form and get
160+
// element information to properly set default element values nested
161+
// inside the form.
162+
if ($targetWebform = Webform::load($form['#webform_id'] ?? NULL)) {
163+
foreach ($data as $key => $value) {
164+
if ($targetElement = $targetWebform->getElement($key)) {
165+
if ($element = &NestedArray::getValue($form['elements'], $targetElement['#webform_parents'])) {
166+
$element['#default_value'] = $value;
167+
}
168+
}
158169
}
159170
}
160171
}

modules/os2forms_forloeb/src/Plugin/WebformHandler/MaestroNotificationHandler.php

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $formStat
9999
'#title' => $this->t('Notification'),
100100
];
101101

102-
$availableElements = $this->getRecipientElements();
102+
$availableElements = $this->getRecipientElementOptions();
103103
$form[self::NOTIFICATION][static::RECIPIENT_ELEMENT] = [
104104
'#type' => 'select',
105105
'#title' => $this->t('Element that contains the recipient identifier (email, CPR or CVR) of the notification'),
@@ -228,7 +228,7 @@ public function validateConfigurationForm(array &$form, FormStateInterface $form
228228
/**
229229
* Get recipient elements.
230230
*/
231-
private function getRecipientElements(): array {
231+
private function getRecipientElementOptions(): array {
232232
$elements = $this->getWebform()->getElementsDecodedAndFlattened();
233233

234234
$elementTypes = [
@@ -240,16 +240,60 @@ private function getRecipientElements(): array {
240240
'cvr_value_element',
241241
'os2forms_person_lookup',
242242
];
243+
244+
$isAllowedElement = static fn ($e) => in_array($e['#type'], $elementTypes, TRUE);
245+
246+
// Expand composite elements, NOT custom composite elements.
247+
foreach ($elements as $key => $element) {
248+
$formElement = $this->getWebform()->getElement($key);
249+
250+
if ('webform_custom_composite' === $formElement['#type']) {
251+
continue;
252+
}
253+
254+
if (isset($formElement['#webform_composite_elements'])) {
255+
foreach ($formElement['#webform_composite_elements'] as $compositeElement) {
256+
// If composite element is not accessible ignore it.
257+
if (!($compositeElement['#access'] ?? TRUE)) {
258+
continue;
259+
}
260+
261+
if ($isAllowedElement($compositeElement)) {
262+
// Group composite subelements.
263+
$elements[$element['#title']][$compositeElement['#webform_composite_key']] = [
264+
'#title' => $compositeElement['#title'],
265+
];
266+
267+
$elements[$element['#title']]['#is_composite'] = TRUE;
268+
}
269+
}
270+
}
271+
}
272+
243273
$elements = array_filter(
244274
$elements,
245-
static function (array $element) use ($elementTypes) {
246-
return in_array($element['#type'], $elementTypes, TRUE);
247-
}
275+
static fn (array $element) => $isAllowedElement($element)
276+
// Composite elements are already filtered,
277+
// i.e. they do not need to be filtered here.
278+
|| ($element['#is_composite'] ?? FALSE)
248279
);
249280

250-
return array_map(static function (array $element) {
251-
return $element['#title'];
252-
}, $elements);
281+
// Get titles of remaining elements.
282+
return array_map(
283+
static function (array $element) {
284+
if ($element['#is_composite'] ?? FALSE) {
285+
286+
return array_map(
287+
static fn (array $compositeElement) => $compositeElement['#title'],
288+
// Consider only elements with a title,
289+
// i.e. the subelements we added earlier.
290+
array_filter($element, static fn ($e) => isset($e['#title'])));
291+
}
292+
293+
return $element['#title'];
294+
},
295+
$elements
296+
);
253297
}
254298

255299
/**

modules/os2forms_webform_maps/src/Plugin/WebformElement/WebformLeafletMapField.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public function form(array $form, FormStateInterface $form_state) {
190190
],
191191
],
192192
'polyline_color' => [
193-
'#type' => 'input_color',
193+
'#type' => 'textfield',
194194
'#title' => 'Color',
195195
'#description' => $this->t('Enter value as HEX or CSS color'),
196196
],
@@ -199,7 +199,7 @@ public function form(array $form, FormStateInterface $form_state) {
199199
'#title' => 'Prevent Intersection',
200200
],
201201
'polyline_error_color' => [
202-
'#type' => 'input_color',
202+
'#type' => 'textfield',
203203
'#title' => 'Error color',
204204
'#description' => $this->t('Enter value as HEX or CSS color'),
205205
'#states' => [
@@ -233,7 +233,7 @@ public function form(array $form, FormStateInterface $form_state) {
233233
],
234234
],
235235
'rectangle_color' => [
236-
'#type' => 'input_color',
236+
'#type' => 'textfield',
237237
'#title' => 'Color',
238238
'#description' => $this->t('Enter value as HEX or CSS color'),
239239
],
@@ -253,7 +253,7 @@ public function form(array $form, FormStateInterface $form_state) {
253253
],
254254
],
255255
'polygon_color' => [
256-
'#type' => 'input_color',
256+
'#type' => 'textfield',
257257
'#title' => 'Color',
258258
'#description' => $this->t('Enter value as HEX or CSS color'),
259259
],
@@ -262,7 +262,7 @@ public function form(array $form, FormStateInterface $form_state) {
262262
'#title' => 'Prevent Intersection',
263263
],
264264
'polygon_error_color' => [
265-
'#type' => 'input_color',
265+
'#type' => 'textfield',
266266
'#title' => 'Error color',
267267
'#states' => [
268268
'invisible' => [
@@ -296,7 +296,7 @@ public function form(array $form, FormStateInterface $form_state) {
296296
],
297297
],
298298
'circle_color' => [
299-
'#type' => 'input_color',
299+
'#type' => 'textfield',
300300
'#title' => 'Color',
301301
'#description' => $this->t('Enter value as HEX or CSS color'),
302302
],

src/Form/SettingsForm.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
8585
}
8686

8787
$this->messenger()->addStatus($this->t('The configuration options have been saved.'));
88+
8889
}
8990

9091
}

0 commit comments

Comments
 (0)