Skip to content

Commit

Permalink
Merge branch 'develop' into feature/digital-post-submission-logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jekuaitk authored Dec 5, 2023
2 parents 1efe75e + 2c47532 commit 068cb52
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ before starting to add changes. Use example [placed in the end of the page](#exa

- [#76](https://github.com/OS2Forms/os2forms/pull/76)
Fixed digital post logging on submissions.
- [#74](https://github.com/OS2Forms/os2forms/pull/74)
Allow composite elements in Maestro notification recipient
- [#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

Expand Down
12 changes: 12 additions & 0 deletions modules/os2forms_forloeb/src/MaestroHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -466,6 +467,17 @@ public function renderNotification(WebformSubmissionInterface $submission, strin
?? $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);
$recipient = NestedArray::getValue($data, $keys);
}
}

if ($notificationType === self::NOTIFICATION_ESCALATION) {
$recipient = $settings[MaestroNotificationHandler::NOTIFICATION][$notificationType][MaestroNotificationHandler::NOTIFICATION_RECIPIENT] ?? NULL;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $formStat
'#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'),
Expand Down Expand Up @@ -228,7 +228,7 @@ public function validateConfigurationForm(array &$form, FormStateInterface $form
/**
* Get recipient elements.
*/
private function getRecipientElements(): array {
private function getRecipientElementOptions(): array {
$elements = $this->getWebform()->getElementsDecodedAndFlattened();

$elementTypes = [
Expand All @@ -240,16 +240,60 @@ private function getRecipientElements(): array {
'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) {
$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.
if (!($compositeElement['#access'] ?? TRUE)) {
continue;
}

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) {
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
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
],
Expand All @@ -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' => [
Expand Down Expand Up @@ -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'),
],
Expand All @@ -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'),
],
Expand All @@ -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' => [
Expand Down Expand Up @@ -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'),
],
Expand Down

0 comments on commit 068cb52

Please sign in to comment.