From 2b28709639fd487f9c684aef4f50b81542707100 Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Wed, 8 Nov 2023 10:50:23 +0100 Subject: [PATCH 01/10] SUPP0RT-1293: Allowed composite elements in Maestro notification recipient --- .../os2forms_forloeb/src/MaestroHelper.php | 15 +++++++++++++ .../MaestroNotificationHandler.php | 22 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/modules/os2forms_forloeb/src/MaestroHelper.php b/modules/os2forms_forloeb/src/MaestroHelper.php index ce0b5fbb..565ad236 100644 --- a/modules/os2forms_forloeb/src/MaestroHelper.php +++ b/modules/os2forms_forloeb/src/MaestroHelper.php @@ -466,6 +466,21 @@ public function renderNotification(WebformSubmissionInterface $submission, strin ?? $data[$recipientElement] ?? NULL; + // Handle composite elements. + if ($recipient === NULL) { + if (str_contains($recipientElement, '__')) { + $keys = explode('__', $recipientElement); + $result = $data; + foreach ($keys as $key) { + if (array_key_exists($key, $result)) { + $result = $result[$key]; + } + } + + $recipient = $result; + } + } + if ($notificationType === self::NOTIFICATION_ESCALATION) { $recipient = $settings[MaestroNotificationHandler::NOTIFICATION][$notificationType][MaestroNotificationHandler::NOTIFICATION_RECIPIENT] ?? NULL; } diff --git a/modules/os2forms_forloeb/src/Plugin/WebformHandler/MaestroNotificationHandler.php b/modules/os2forms_forloeb/src/Plugin/WebformHandler/MaestroNotificationHandler.php index d0afc201..f907ba7a 100644 --- a/modules/os2forms_forloeb/src/Plugin/WebformHandler/MaestroNotificationHandler.php +++ b/modules/os2forms_forloeb/src/Plugin/WebformHandler/MaestroNotificationHandler.php @@ -240,6 +240,28 @@ private function getRecipientElements(): array { 'cvr_value_element', 'os2forms_person_lookup', ]; + + // Expand composite elements, NOT custom composite elements. + foreach ($elements as $key => $element) { + $orgElement = $this->getWebform()->getElement($key); + + if (array_key_exists('#webform_composite_elements', $orgElement)) { + foreach ($orgElement['#webform_composite_elements'] as $compositeElement) { + // If composite element is not accessible ignore it. + if (array_key_exists('#access', $compositeElement) && !$compositeElement['#access']) { + continue; + } + + if (in_array($compositeElement['#type'], $elementTypes, TRUE)) { + $elements[$compositeElement['#webform_composite_key']] = [ + '#title' => (string) $compositeElement['#title'], + '#type' => $compositeElement['#type'], + ]; + } + } + } + } + $elements = array_filter( $elements, static function (array $element) use ($elementTypes) { From 0bb05b04bed493bbd2fc048501b45cc12ebf3883 Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Wed, 8 Nov 2023 11:02:10 +0100 Subject: [PATCH 02/10] SUPP0RT-1293: Updated CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c03d94f7..a79db989 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ before starting to add changes. Use example [placed in the end of the page](#exa ## [Unreleased] +- [#74](https://github.com/OS2Forms/os2forms/pull/74) + Allow composite elements in Maestro notification recipient - [#72](https://github.com/OS2Forms/os2forms/pull/72) Fix certificate testing, also testing for RSA/PEM certs as well as PKCS12 From 4bfe84339202ff9534686a4c0caa088f82e9554b Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Wed, 8 Nov 2023 14:29:05 +0100 Subject: [PATCH 03/10] SUPP0RT-1293: Cleanup --- modules/os2forms_forloeb/src/MaestroHelper.php | 13 +++++-------- .../WebformHandler/MaestroNotificationHandler.php | 8 ++++---- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/modules/os2forms_forloeb/src/MaestroHelper.php b/modules/os2forms_forloeb/src/MaestroHelper.php index 565ad236..5f73611e 100644 --- a/modules/os2forms_forloeb/src/MaestroHelper.php +++ b/modules/os2forms_forloeb/src/MaestroHelper.php @@ -8,6 +8,7 @@ use Drupal\advancedqueue\Job; use Drupal\advancedqueue\JobResult; use Drupal\Component\Render\MarkupInterface; +use Drupal\Component\Utility\NestedArray; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Config\ImmutableConfig; use Drupal\Core\Entity\EntityStorageInterface; @@ -468,16 +469,12 @@ public function renderNotification(WebformSubmissionInterface $submission, strin // Handle composite elements. if ($recipient === NULL) { + // Composite subelement keys consist of + // the composite element key and the subelement key separated by '__', + // e.g. 'contact__name' if (str_contains($recipientElement, '__')) { $keys = explode('__', $recipientElement); - $result = $data; - foreach ($keys as $key) { - if (array_key_exists($key, $result)) { - $result = $result[$key]; - } - } - - $recipient = $result; + $recipient = NestedArray::getValue($data, $keys); } } diff --git a/modules/os2forms_forloeb/src/Plugin/WebformHandler/MaestroNotificationHandler.php b/modules/os2forms_forloeb/src/Plugin/WebformHandler/MaestroNotificationHandler.php index f907ba7a..ab721dda 100644 --- a/modules/os2forms_forloeb/src/Plugin/WebformHandler/MaestroNotificationHandler.php +++ b/modules/os2forms_forloeb/src/Plugin/WebformHandler/MaestroNotificationHandler.php @@ -243,12 +243,12 @@ private function getRecipientElements(): array { // Expand composite elements, NOT custom composite elements. foreach ($elements as $key => $element) { - $orgElement = $this->getWebform()->getElement($key); + $formElement = $this->getWebform()->getElement($key); - if (array_key_exists('#webform_composite_elements', $orgElement)) { - foreach ($orgElement['#webform_composite_elements'] as $compositeElement) { + if (isset($formElement['#webform_composite_elements'])) { + foreach ($formElement['#webform_composite_elements'] as $compositeElement) { // If composite element is not accessible ignore it. - if (array_key_exists('#access', $compositeElement) && !$compositeElement['#access']) { + if (!($compositeElement['#access'] ?? TRUE)) { continue; } From 4303abd455aa3d678bb5ad9b44925f1199ead45a Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Wed, 8 Nov 2023 14:34:11 +0100 Subject: [PATCH 04/10] SUPP0RT-1293: Applied coding standards --- modules/os2forms_forloeb/src/MaestroHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/os2forms_forloeb/src/MaestroHelper.php b/modules/os2forms_forloeb/src/MaestroHelper.php index 5f73611e..dfa65cae 100644 --- a/modules/os2forms_forloeb/src/MaestroHelper.php +++ b/modules/os2forms_forloeb/src/MaestroHelper.php @@ -471,7 +471,7 @@ public function renderNotification(WebformSubmissionInterface $submission, strin if ($recipient === NULL) { // Composite subelement keys consist of // the composite element key and the subelement key separated by '__', - // e.g. 'contact__name' + // e.g. 'contact__name'. if (str_contains($recipientElement, '__')) { $keys = explode('__', $recipientElement); $recipient = NestedArray::getValue($data, $keys); From 3c4fda0b470780bdeb4f48b5fd73ed9c3b90c48b Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Wed, 8 Nov 2023 16:03:25 +0100 Subject: [PATCH 05/10] SUPP0RT-1293: Cleanup --- .../MaestroNotificationHandler.php | 41 +++++++++++++------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/modules/os2forms_forloeb/src/Plugin/WebformHandler/MaestroNotificationHandler.php b/modules/os2forms_forloeb/src/Plugin/WebformHandler/MaestroNotificationHandler.php index ab721dda..33452747 100644 --- a/modules/os2forms_forloeb/src/Plugin/WebformHandler/MaestroNotificationHandler.php +++ b/modules/os2forms_forloeb/src/Plugin/WebformHandler/MaestroNotificationHandler.php @@ -99,7 +99,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $formStat '#title' => $this->t('Notification'), ]; - $availableElements = $this->getRecipientElements(); + $availableElements = $this->getRecipientElementsOptions(); $form[self::NOTIFICATION][static::RECIPIENT_ELEMENT] = [ '#type' => 'select', '#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 /** * Get recipient elements. */ - private function getRecipientElements(): array { + private function getRecipientElementsOptions(): array { $elements = $this->getWebform()->getElementsDecodedAndFlattened(); $elementTypes = [ @@ -241,6 +241,8 @@ private function getRecipientElements(): array { 'os2forms_person_lookup', ]; + $isAllowedElement = static fn ($e) => in_array($e['#type'], $elementTypes, TRUE); + // Expand composite elements, NOT custom composite elements. foreach ($elements as $key => $element) { $formElement = $this->getWebform()->getElement($key); @@ -252,11 +254,13 @@ private function getRecipientElements(): array { continue; } - if (in_array($compositeElement['#type'], $elementTypes, TRUE)) { - $elements[$compositeElement['#webform_composite_key']] = [ - '#title' => (string) $compositeElement['#title'], - '#type' => $compositeElement['#type'], + if ($isAllowedElement($compositeElement)) { + // Group composite subelements. + $elements[$element['#title']][$compositeElement['#webform_composite_key']] = [ + '#title' => $compositeElement['#title'], ]; + + $elements[$element['#title']]['#is_composite'] = TRUE; } } } @@ -264,14 +268,27 @@ private function getRecipientElements(): array { $elements = array_filter( $elements, - static function (array $element) use ($elementTypes) { - return in_array($element['#type'], $elementTypes, TRUE); - } + static fn (array $element) => $isAllowedElement($element) + // Composite elements are already filtered, + //i.e. they do not need to be filtered here. + || ($element['#is_composite'] ?? FALSE) ); - return array_map(static function (array $element) { - return $element['#title']; - }, $elements); + // Get titles of remaining elements. + return array_map( + static function (array $element) { + if ($element['#is_composite'] ?? FALSE) { + + return array_map( + static fn (array $compositeElement) => $compositeElement['#title'], + // Consider only elements with a title, i.e. the subelements we added earlier. + array_filter($element, static fn ($e) => isset($e['#title']))); + } + + return $element['#title']; + }, + $elements + ); } /** From 6822b808792d22e09338dfaf4eb9d20e2b5fd9a4 Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Wed, 8 Nov 2023 16:05:55 +0100 Subject: [PATCH 06/10] SUPP0RT-1293: Applied coding standards --- .../Plugin/WebformHandler/MaestroNotificationHandler.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/os2forms_forloeb/src/Plugin/WebformHandler/MaestroNotificationHandler.php b/modules/os2forms_forloeb/src/Plugin/WebformHandler/MaestroNotificationHandler.php index 33452747..93136bbc 100644 --- a/modules/os2forms_forloeb/src/Plugin/WebformHandler/MaestroNotificationHandler.php +++ b/modules/os2forms_forloeb/src/Plugin/WebformHandler/MaestroNotificationHandler.php @@ -99,7 +99,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $formStat '#title' => $this->t('Notification'), ]; - $availableElements = $this->getRecipientElementsOptions(); + $availableElements = $this->getRecipientElementOptions(); $form[self::NOTIFICATION][static::RECIPIENT_ELEMENT] = [ '#type' => 'select', '#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 /** * Get recipient elements. */ - private function getRecipientElementsOptions(): array { + private function getRecipientElementOptions(): array { $elements = $this->getWebform()->getElementsDecodedAndFlattened(); $elementTypes = [ @@ -270,7 +270,7 @@ private function getRecipientElementsOptions(): array { $elements, static fn (array $element) => $isAllowedElement($element) // Composite elements are already filtered, - //i.e. they do not need to be filtered here. + // i.e. they do not need to be filtered here. || ($element['#is_composite'] ?? FALSE) ); @@ -281,7 +281,8 @@ static function (array $element) { return array_map( static fn (array $compositeElement) => $compositeElement['#title'], - // Consider only elements with a title, i.e. the subelements we added earlier. + // Consider only elements with a title, + // i.e. the subelements we added earlier. array_filter($element, static fn ($e) => isset($e['#title']))); } From 0e30622f25a5b4402f5d6e1b45a5570a291b9804 Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Thu, 9 Nov 2023 09:14:09 +0100 Subject: [PATCH 07/10] SUPP0RT-1293: Ignored custom composite elements --- .../src/Plugin/WebformHandler/MaestroNotificationHandler.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/os2forms_forloeb/src/Plugin/WebformHandler/MaestroNotificationHandler.php b/modules/os2forms_forloeb/src/Plugin/WebformHandler/MaestroNotificationHandler.php index 93136bbc..35c32d87 100644 --- a/modules/os2forms_forloeb/src/Plugin/WebformHandler/MaestroNotificationHandler.php +++ b/modules/os2forms_forloeb/src/Plugin/WebformHandler/MaestroNotificationHandler.php @@ -247,6 +247,10 @@ private function getRecipientElementOptions(): array { foreach ($elements as $key => $element) { $formElement = $this->getWebform()->getElement($key); + if ('webform_custom_composite' === $formElement['#type']) { + continue; + } + if (isset($formElement['#webform_composite_elements'])) { foreach ($formElement['#webform_composite_elements'] as $compositeElement) { // If composite element is not accessible ignore it. From a19b7b6bb59abee5eb0fa62871a9f9e762651b43 Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Thu, 9 Nov 2023 09:19:18 +0100 Subject: [PATCH 08/10] SUPP0RT-1293: Applied coding standards --- .../src/Plugin/WebformHandler/MaestroNotificationHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/os2forms_forloeb/src/Plugin/WebformHandler/MaestroNotificationHandler.php b/modules/os2forms_forloeb/src/Plugin/WebformHandler/MaestroNotificationHandler.php index 35c32d87..02c7f943 100644 --- a/modules/os2forms_forloeb/src/Plugin/WebformHandler/MaestroNotificationHandler.php +++ b/modules/os2forms_forloeb/src/Plugin/WebformHandler/MaestroNotificationHandler.php @@ -248,7 +248,7 @@ private function getRecipientElementOptions(): array { $formElement = $this->getWebform()->getElement($key); if ('webform_custom_composite' === $formElement['#type']) { - continue; + continue; } if (isset($formElement['#webform_composite_elements'])) { From ee3ce190581021d864a2ef21524756851e3a418f Mon Sep 17 00:00:00 2001 From: Jeppe Krogh Date: Wed, 29 Nov 2023 12:41:11 +0100 Subject: [PATCH 09/10] changed color field types from input_color to textfield --- .../Plugin/WebformElement/WebformLeafletMapField.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/os2forms_webform_maps/src/Plugin/WebformElement/WebformLeafletMapField.php b/modules/os2forms_webform_maps/src/Plugin/WebformElement/WebformLeafletMapField.php index 290b1a64..d6a5afea 100644 --- a/modules/os2forms_webform_maps/src/Plugin/WebformElement/WebformLeafletMapField.php +++ b/modules/os2forms_webform_maps/src/Plugin/WebformElement/WebformLeafletMapField.php @@ -190,7 +190,7 @@ public function form(array $form, FormStateInterface $form_state) { ], ], 'polyline_color' => [ - '#type' => 'input_color', + '#type' => 'textfield', '#title' => 'Color', '#description' => $this->t('Enter value as HEX or CSS color'), ], @@ -199,7 +199,7 @@ public function form(array $form, FormStateInterface $form_state) { '#title' => 'Prevent Intersection', ], 'polyline_error_color' => [ - '#type' => 'input_color', + '#type' => 'textfield', '#title' => 'Error color', '#description' => $this->t('Enter value as HEX or CSS color'), '#states' => [ @@ -233,7 +233,7 @@ public function form(array $form, FormStateInterface $form_state) { ], ], 'rectangle_color' => [ - '#type' => 'input_color', + '#type' => 'textfield', '#title' => 'Color', '#description' => $this->t('Enter value as HEX or CSS color'), ], @@ -253,7 +253,7 @@ public function form(array $form, FormStateInterface $form_state) { ], ], 'polygon_color' => [ - '#type' => 'input_color', + '#type' => 'textfield', '#title' => 'Color', '#description' => $this->t('Enter value as HEX or CSS color'), ], @@ -262,7 +262,7 @@ public function form(array $form, FormStateInterface $form_state) { '#title' => 'Prevent Intersection', ], 'polygon_error_color' => [ - '#type' => 'input_color', + '#type' => 'textfield', '#title' => 'Error color', '#states' => [ 'invisible' => [ @@ -296,7 +296,7 @@ public function form(array $form, FormStateInterface $form_state) { ], ], 'circle_color' => [ - '#type' => 'input_color', + '#type' => 'textfield', '#title' => 'Color', '#description' => $this->t('Enter value as HEX or CSS color'), ], From 5646a2bfd1faff3961492dfa0cbaf84adbe527b5 Mon Sep 17 00:00:00 2001 From: Jeppe Krogh Date: Thu, 30 Nov 2023 09:21:52 +0100 Subject: [PATCH 10/10] updated changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 88e04657..b0c5cabe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ before starting to add changes. Use example [placed in the end of the page](#exa - [#73](https://github.com/OS2Forms/os2forms/pull/73a) Fix issue with nested elements in webform inherit +- [#77](https://github.com/OS2Forms/os2forms/pull/77) + Fix color picker fields in os2forms_webform_maps ## [3.13.2] 2023-10-19