Skip to content

Commit

Permalink
Merge pull request #55 from OS2Forms/develop
Browse files Browse the repository at this point in the history
OS-55 + OS-56
  • Loading branch information
skifter authored Aug 23, 2023
2 parents 1da8ba5 + 0f96a9c commit e14d7cc
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 54 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ before starting to add changes. Use example [placed in the end of the page](#exa

## [Unreleased]

- [OSF-55] DAWA Address-Matrikula (autocomplete) (required)
- [OSF-56] DAWA Address-Matrikula (autocomplete) (value in XML-file)

## [3.9.0] 2023-08-22

- [OS-57] - SBSIP XML element - Computed TWIG
Expand Down
107 changes: 53 additions & 54 deletions modules/os2forms_dawa/src/Element/DawaElementAddressMatrikula.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,64 +18,63 @@ class DawaElementAddressMatrikula extends WebformCompositeBase {
*/
public static function getCompositeElements(array $element) {
$elements = [];
if ($element) {
$elements['address'] = [
'#type' => 'os2forms_dawa_address',
'#title' => $element['#address_field_title'] ?? t('Address'),
'#remove_place_name' => $element['#remove_place_name'] ?? FALSE,
'#remove_code' => $element['#remove_code'] ?? FALSE,
'#limit_by_municipality' => $element['#limit_by_municipality'] ?? FALSE,
];

$elements['matrikula'] = [
'#type' => 'select',
'#title' => $element['#matrikula_field_title'] ?? t('Matrikula'),
'#options' => [],
'#empty_value' => NULL,
'#validated' => TRUE,
'#attributes' => [
'disabled' => 'disabled',
$elements['address'] = [
'#type' => 'os2forms_dawa_address',
'#title' => $element['#address_field_title'] ?? t('Address'),
'#remove_place_name' => $element['#remove_place_name'] ?? FALSE,
'#remove_code' => $element['#remove_code'] ?? FALSE,
'#limit_by_municipality' => $element['#limit_by_municipality'] ?? FALSE,
];

$elements['matrikula'] = [
'#type' => 'select',
'#title' => $element['#matrikula_field_title'] ?? t('Matrikula'),
'#options' => [],
'#empty_value' => NULL,
'#validated' => TRUE,
'#attributes' => [
'disabled' => 'disabled',
],
'#description' => t('Options autofill is disabled during the element preview'),
];

// If that is just element preview (no webform_id), then keep the
// element simple. Don't add AJAX behaviour.
if (isset($element['#webform_id'])) {
$matrikula_wrapper_id = $element['#webform_id'] . '-matrikula-wrapper';

$elements['address']['#ajax'] = [
'callback' => [
DawaElementAddressMatrikula::class,
'matrikulaUpdateSelectOptions',
],
'event' => 'change',
'wrapper' => $matrikula_wrapper_id,
'progress' => [
'type' => 'none',
],
'#description' => t('Options autofill is disabled during the element preview'),
];

// If that is just element preview (no webform_id), then keep the
// element simple. Don't add AJAX behaviour.
if (isset($element['#webform_id'])) {
$matrikula_wrapper_id = $element['#webform_id'] . '-matrikula-wrapper';

$elements['address']['#ajax'] = [
'callback' => [
DawaElementAddressMatrikula::class,
'matrikulaUpdateSelectOptions',
],
'event' => 'change',
'wrapper' => $matrikula_wrapper_id,
'progress' => [
'type' => 'none',
],
];

$elements['matrikula'] += [
'#prefix' => '<div id="' . $matrikula_wrapper_id . '">',
'#suffix' => '</div>',
];
unset($elements['matrikula']['#description']);

if (isset($element['#value']) && !empty($element['#value']['address'])) {
$addressValue = $element['#value']['address'];

$matrikulaOptions = self::getMatrikulaOptions($addressValue, $element);

// Populating the element.
if (!empty($matrikulaOptions)) {
$elements['matrikula']['#options'] = $matrikulaOptions;
$matrikulaOptionKeys = array_keys($matrikulaOptions);
$elements['matrikula']['matrikula']['#value'] = reset($matrikulaOptionKeys);

// Make element enabled.
unset($elements['matrikula']['#attributes']['disabled']);
}
$elements['matrikula'] += [
'#prefix' => '<div id="' . $matrikula_wrapper_id . '">',
'#suffix' => '</div>',
];
unset($elements['matrikula']['#description']);

if (isset($element['#value']) && !empty($element['#value']['address'])) {
$addressValue = $element['#value']['address'];

$matrikulaOptions = self::getMatrikulaOptions($addressValue, $element);

// Populating the element.
if (!empty($matrikulaOptions)) {
$elements['matrikula']['#options'] = $matrikulaOptions;
$matrikulaOptionKeys = array_keys($matrikulaOptions);
$elements['matrikula']['matrikula']['#value'] = reset($matrikulaOptionKeys);

// Make element enabled.
unset($elements['matrikula']['#attributes']['disabled']);
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions modules/os2forms_sbsys/src/Element/WebformAttachmentSbsysXml.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ protected static function getWebformElementsAsList(WebformSubmissionInterface $w
$field_name = $key;
$field_name = preg_replace('/\W/', '_', $field_name);
$webform_element['#type'];

if ($webform_element['#type'] == 'markup') {
$elements_list[$field_name] = $webform_element['value'];
}
Expand All @@ -241,9 +242,18 @@ protected static function getWebformElementsAsList(WebformSubmissionInterface $w
}
else {
$elements_list[$field_name] = $data[$key];

// For arrays (for example: composite elements),
// values are aldo duplicated by splitting them.
if (is_array($data[$key])) {
foreach ($data[$key] as $child_key => $child_data) {
$elements_list[$field_name . "_" . $child_key] = $child_data;
}
}
}
}
}

return $elements_list;
}

Expand Down

0 comments on commit e14d7cc

Please sign in to comment.