-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SUPP0RT-1293: Updated os2forms maestro handler patch
- Loading branch information
Showing
1 changed file
with
82 additions
and
22 deletions.
There are no files selected for viewing
104 changes: 82 additions & 22 deletions
104
patches/drupal/os2forms/allow_composite_elements_in_maestro_notification_recipient.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,119 @@ | ||
diff --git a/modules/os2forms_forloeb/src/MaestroHelper.php b/modules/os2forms_forloeb/src/MaestroHelper.php | ||
index ce0b5fb..565ad23 100644 | ||
index ce0b5fb..dfa65ca 100644 | ||
--- a/modules/os2forms_forloeb/src/MaestroHelper.php | ||
+++ b/modules/os2forms_forloeb/src/MaestroHelper.php | ||
@@ -466,6 +466,21 @@ class MaestroHelper implements LoggerInterface { | ||
@@ -8,6 +8,7 @@ use Drupal\advancedqueue\Entity\QueueInterface; | ||
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; | ||
@@ -466,6 +467,17 @@ class MaestroHelper implements LoggerInterface { | ||
?? $data[$recipientElement] | ||
?? NULL; | ||
|
||
+ // 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); | ||
+ } | ||
+ } | ||
+ | ||
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 d0afc20..f907ba7 100644 | ||
index d0afc20..35c32d8 100644 | ||
--- a/modules/os2forms_forloeb/src/Plugin/WebformHandler/MaestroNotificationHandler.php | ||
+++ b/modules/os2forms_forloeb/src/Plugin/WebformHandler/MaestroNotificationHandler.php | ||
@@ -240,6 +240,28 @@ final class MaestroNotificationHandler extends WebformHandlerBase { | ||
@@ -99,7 +99,7 @@ final class MaestroNotificationHandler extends WebformHandlerBase { | ||
'#title' => $this->t('Notification'), | ||
]; | ||
|
||
- $availableElements = $this->getRecipientElements(); | ||
+ $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 @@ final class MaestroNotificationHandler extends WebformHandlerBase { | ||
/** | ||
* Get recipient elements. | ||
*/ | ||
- private function getRecipientElements(): array { | ||
+ private function getRecipientElementOptions(): array { | ||
$elements = $this->getWebform()->getElementsDecodedAndFlattened(); | ||
|
||
$elementTypes = [ | ||
@@ -240,16 +240,60 @@ final class MaestroNotificationHandler extends WebformHandlerBase { | ||
'cvr_value_element', | ||
'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) { | ||
+ $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 ('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. | ||
+ if (array_key_exists('#access', $compositeElement) && !$compositeElement['#access']) { | ||
+ if (!($compositeElement['#access'] ?? TRUE)) { | ||
+ 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; | ||
+ } | ||
+ } | ||
+ } | ||
+ } | ||
+ | ||
$elements = array_filter( | ||
$elements, | ||
static function (array $element) use ($elementTypes) { | ||
- 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 | ||
+ ); | ||
} | ||
|
||
/** |