From 306b988b612ed98e4f359b3510ac48fa2b305d38 Mon Sep 17 00:00:00 2001 From: Stanislav Kutasevits Date: Fri, 22 Dec 2023 10:32:49 +0200 Subject: [PATCH 01/15] S2FRMS-40 adding child select fields --- CHANGELOG.md | 2 + .../src/Element/MitidChildAddress.php | 64 +++++++++++++ .../src/Element/MitidChildApartmentNr.php | 64 +++++++++++++ .../src/Element/MitidChildCity.php | 64 +++++++++++++ .../src/Element/MitidChildCoaddress.php | 64 +++++++++++++ .../src/Element/MitidChildCpr.php | 64 +++++++++++++ .../src/Element/MitidChildFloor.php | 64 +++++++++++++ .../src/Element/MitidChildHouseNr.php | 64 +++++++++++++ .../src/Element/MitidChildKommunekode.php | 64 +++++++++++++ .../src/Element/MitidChildName.php | 64 +++++++++++++ .../src/Element/MitidChildPostalCode.php | 64 +++++++++++++ .../src/Element/MitidChildStreet.php | 64 +++++++++++++ .../MitidChildrenSelectAjaxBehaviour.php | 92 +++++++++++++++++++ .../src/Element/NemidChildrenRadios.php | 15 +++ .../src/Element/NemidChildrenSelect.php | 16 ++++ .../WebformElement/MitidChildAddress.php | 19 ++++ .../WebformElement/MitidChildApartmentNr.php | 19 ++++ .../Plugin/WebformElement/MitidChildCity.php | 19 ++++ .../WebformElement/MitidChildCoaddress.php | 19 ++++ .../Plugin/WebformElement/MitidChildCpr.php | 19 ++++ .../WebformElement/MitidChildElementBase.php | 60 ++++++++++++ .../Plugin/WebformElement/MitidChildFloor.php | 19 ++++ .../WebformElement/MitidChildHouseNr.php | 19 ++++ .../WebformElement/MitidChildKommunekode.php | 19 ++++ .../Plugin/WebformElement/MitidChildName.php | 19 ++++ .../WebformElement/MitidChildPostalCode.php | 19 ++++ .../WebformElement/MitidChildStreet.php | 19 ++++ .../WebformElement/NemidChildrenRadios.php | 20 +--- .../WebformElement/NemidChildrenSelect.php | 20 +--- .../src/Service/FormsHelper.php | 2 +- 30 files changed, 1105 insertions(+), 35 deletions(-) create mode 100644 modules/os2forms_nemid/src/Element/MitidChildAddress.php create mode 100644 modules/os2forms_nemid/src/Element/MitidChildApartmentNr.php create mode 100644 modules/os2forms_nemid/src/Element/MitidChildCity.php create mode 100644 modules/os2forms_nemid/src/Element/MitidChildCoaddress.php create mode 100644 modules/os2forms_nemid/src/Element/MitidChildCpr.php create mode 100644 modules/os2forms_nemid/src/Element/MitidChildFloor.php create mode 100644 modules/os2forms_nemid/src/Element/MitidChildHouseNr.php create mode 100644 modules/os2forms_nemid/src/Element/MitidChildKommunekode.php create mode 100644 modules/os2forms_nemid/src/Element/MitidChildName.php create mode 100644 modules/os2forms_nemid/src/Element/MitidChildPostalCode.php create mode 100644 modules/os2forms_nemid/src/Element/MitidChildStreet.php create mode 100644 modules/os2forms_nemid/src/Element/MitidChildrenSelectAjaxBehaviour.php create mode 100644 modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildAddress.php create mode 100644 modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildApartmentNr.php create mode 100644 modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildCity.php create mode 100644 modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildCoaddress.php create mode 100644 modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildCpr.php create mode 100644 modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildElementBase.php create mode 100644 modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildFloor.php create mode 100644 modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildHouseNr.php create mode 100644 modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildKommunekode.php create mode 100644 modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildName.php create mode 100644 modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildPostalCode.php create mode 100644 modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildStreet.php diff --git a/CHANGELOG.md b/CHANGELOG.md index f4af33ef..8643264b 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] +- [S2FRMS-40] Adding child select autopopulate fields + ## [3.13.3] 2023-12-05 - [#76](https://github.com/OS2Forms/os2forms/pull/76) diff --git a/modules/os2forms_nemid/src/Element/MitidChildAddress.php b/modules/os2forms_nemid/src/Element/MitidChildAddress.php new file mode 100644 index 00000000..f8daa7a6 --- /dev/null +++ b/modules/os2forms_nemid/src/Element/MitidChildAddress.php @@ -0,0 +1,64 @@ + [ + [$class, 'processMitidChildAddress'], + [$class, 'processAjaxForm'], + ], + '#element_validate' => [ + [$class, 'validateMitidChildAddress'], + ], + '#pre_render' => [ + [$class, 'preRenderMitidChildAddress'], + ], + '#theme' => 'input__os2forms_mitid_child_address', + ]; + } + + /** + * Processes a 'os2forms_mitid_child_address' element. + */ + public static function processMitidChildAddress(&$element, FormStateInterface $form_state, &$complete_form) { + // Here you can add and manipulate your element's properties and callbacks. + return $element; + } + + /** + * Webform element validation handler for #type 'os2forms_mitid_child_address'. + */ + public static function validateMitidChildAddress(&$element, FormStateInterface $form_state, &$complete_form) { + // Here you can add custom validation logic. + } + + /** + * {@inheritdoc} + */ + public static function preRenderMitidChildAddress(array $element) { + $element = parent::prerenderNemidElementBase($element); + static::setAttributes($element, ['form-text', 'os2forms-mitid-child-address']); + return $element; + } + +} diff --git a/modules/os2forms_nemid/src/Element/MitidChildApartmentNr.php b/modules/os2forms_nemid/src/Element/MitidChildApartmentNr.php new file mode 100644 index 00000000..65cecc7b --- /dev/null +++ b/modules/os2forms_nemid/src/Element/MitidChildApartmentNr.php @@ -0,0 +1,64 @@ + [ + [$class, 'processMitidChildApartmentNr'], + [$class, 'processAjaxForm'], + ], + '#element_validate' => [ + [$class, 'validateMitidChildApartmentNr'], + ], + '#pre_render' => [ + [$class, 'preRenderMitidChildApartmentNr'], + ], + '#theme' => 'input__os2forms_mitid_child_apartmentNr', + ]; + } + + /** + * Processes a 'os2forms_mitid_child_apartmentNr' element. + */ + public static function processMitidChildApartmentNr(&$element, FormStateInterface $form_state, &$complete_form) { + // Here you can add and manipulate your element's properties and callbacks. + return $element; + } + + /** + * Webform element validation handler for #type 'os2forms_mitid_child_apartmentNr'. + */ + public static function validateMitidChildApartmentNr(&$element, FormStateInterface $form_state, &$complete_form) { + // Here you can add custom validation logic. + } + + /** + * {@inheritdoc} + */ + public static function preRenderMitidChildApartmentNr(array $element) { + $element = parent::prerenderNemidElementBase($element); + static::setAttributes($element, ['form-text', 'os2forms-mitid-child-apartment-nr']); + return $element; + } + +} diff --git a/modules/os2forms_nemid/src/Element/MitidChildCity.php b/modules/os2forms_nemid/src/Element/MitidChildCity.php new file mode 100644 index 00000000..8ce47265 --- /dev/null +++ b/modules/os2forms_nemid/src/Element/MitidChildCity.php @@ -0,0 +1,64 @@ + [ + [$class, 'processMitidChildCity'], + [$class, 'processAjaxForm'], + ], + '#element_validate' => [ + [$class, 'validateMitidChildCity'], + ], + '#pre_render' => [ + [$class, 'preRenderMitidChildCity'], + ], + '#theme' => 'input__os2forms_mitid_child_city', + ]; + } + + /** + * Processes a 'os2forms_mitid_child_city' element. + */ + public static function processMitidChildCity(&$element, FormStateInterface $form_state, &$complete_form) { + // Here you can add and manipulate your element's properties and callbacks. + return $element; + } + + /** + * Webform element validation handler for #type 'os2forms_mitid_child_city'. + */ + public static function validateMitidChildCity(&$element, FormStateInterface $form_state, &$complete_form) { + // Here you can add custom validation logic. + } + + /** + * {@inheritdoc} + */ + public static function preRenderMitidChildCity(array $element) { + $element = parent::prerenderNemidElementBase($element); + static::setAttributes($element, ['form-text', 'os2forms-mitid-child-city']); + return $element; + } + +} diff --git a/modules/os2forms_nemid/src/Element/MitidChildCoaddress.php b/modules/os2forms_nemid/src/Element/MitidChildCoaddress.php new file mode 100644 index 00000000..87fd6be0 --- /dev/null +++ b/modules/os2forms_nemid/src/Element/MitidChildCoaddress.php @@ -0,0 +1,64 @@ + [ + [$class, 'processMitidChildCoaddress'], + [$class, 'processAjaxForm'], + ], + '#element_validate' => [ + [$class, 'validateMitidChildCoaddress'], + ], + '#pre_render' => [ + [$class, 'preRenderMitidChildCoaddress'], + ], + '#theme' => 'input__os2forms_mitid_child_coaddress', + ]; + } + + /** + * Processes a 'os2forms_mitid_child_coaddress' element. + */ + public static function processMitidChildCoaddress(&$element, FormStateInterface $form_state, &$complete_form) { + // Here you can add and manipulate your element's properties and callbacks. + return $element; + } + + /** + * Webform element validation handler for #type 'os2forms_mitid_child_coaddress'. + */ + public static function validateMitidChildCoaddress(&$element, FormStateInterface $form_state, &$complete_form) { + // Here you can add custom validation logic. + } + + /** + * {@inheritdoc} + */ + public static function preRenderMitidChildCoaddress(array $element) { + $element = parent::prerenderNemidElementBase($element); + static::setAttributes($element, ['form-text', 'os2forms-mitid-child-coaddress']); + return $element; + } + +} diff --git a/modules/os2forms_nemid/src/Element/MitidChildCpr.php b/modules/os2forms_nemid/src/Element/MitidChildCpr.php new file mode 100644 index 00000000..1ea9c566 --- /dev/null +++ b/modules/os2forms_nemid/src/Element/MitidChildCpr.php @@ -0,0 +1,64 @@ + [ + [$class, 'processMitidChildCpr'], + [$class, 'processAjaxForm'], + ], + '#element_validate' => [ + [$class, 'validateMitidChildCpr'], + ], + '#pre_render' => [ + [$class, 'preRenderMitidChildCpr'], + ], + '#theme' => 'input__os2forms_mitid_child_cpr', + ]; + } + + /** + * Processes a 'os2forms_mitid_child_cpr' element. + */ + public static function processMitidChildCpr(&$element, FormStateInterface $form_state, &$complete_form) { + // Here you can add and manipulate your element's properties and callbacks. + return $element; + } + + /** + * Webform element validation handler for #type 'os2forms_mitid_child_cpr'. + */ + public static function validateMitidChildCpr(&$element, FormStateInterface $form_state, &$complete_form) { + // Here you can add custom validation logic. + } + + /** + * {@inheritdoc} + */ + public static function preRenderMitidChildCpr(array $element) { + $element = parent::prerenderNemidElementBase($element); + static::setAttributes($element, ['form-text', 'os2forms-mitid-child-cpr']); + return $element; + } + +} diff --git a/modules/os2forms_nemid/src/Element/MitidChildFloor.php b/modules/os2forms_nemid/src/Element/MitidChildFloor.php new file mode 100644 index 00000000..49e14cf4 --- /dev/null +++ b/modules/os2forms_nemid/src/Element/MitidChildFloor.php @@ -0,0 +1,64 @@ + [ + [$class, 'processMitidChildFloor'], + [$class, 'processAjaxForm'], + ], + '#element_validate' => [ + [$class, 'validateMitidChildFloor'], + ], + '#pre_render' => [ + [$class, 'preRenderMitidChildFloor'], + ], + '#theme' => 'input__os2forms_mitid_child_floor', + ]; + } + + /** + * Processes a 'os2forms_mitid_child_floor' element. + */ + public static function processMitidChildFloor(&$element, FormStateInterface $form_state, &$complete_form) { + // Here you can add and manipulate your element's properties and callbacks. + return $element; + } + + /** + * Webform element validation handler for #type 'os2forms_mitid_child_floor'. + */ + public static function validateMitidChildFloor(&$element, FormStateInterface $form_state, &$complete_form) { + // Here you can add custom validation logic. + } + + /** + * {@inheritdoc} + */ + public static function preRenderMitidChildFloor(array $element) { + $element = parent::prerenderNemidElementBase($element); + static::setAttributes($element, ['form-text', 'os2forms-mitid-child-floor']); + return $element; + } + +} diff --git a/modules/os2forms_nemid/src/Element/MitidChildHouseNr.php b/modules/os2forms_nemid/src/Element/MitidChildHouseNr.php new file mode 100644 index 00000000..f07e3d6a --- /dev/null +++ b/modules/os2forms_nemid/src/Element/MitidChildHouseNr.php @@ -0,0 +1,64 @@ + [ + [$class, 'processMitidChildHouseNr'], + [$class, 'processAjaxForm'], + ], + '#element_validate' => [ + [$class, 'validateMitidChildHouseNr'], + ], + '#pre_render' => [ + [$class, 'preRenderMitidChildHouseNr'], + ], + '#theme' => 'input__os2forms_mitid_child_house_nr', + ]; + } + + /** + * Processes a 'os2forms_mitid_child_house_nr' element. + */ + public static function processMitidChildHouseNr(&$element, FormStateInterface $form_state, &$complete_form) { + // Here you can add and manipulate your element's properties and callbacks. + return $element; + } + + /** + * Webform element validation handler for #type 'os2forms_mitid_child_house_nr'. + */ + public static function validateMitidChildHouseNr(&$element, FormStateInterface $form_state, &$complete_form) { + // Here you can add custom validation logic. + } + + /** + * {@inheritdoc} + */ + public static function preRenderMitidChildHouseNr(array $element) { + $element = parent::prerenderNemidElementBase($element); + static::setAttributes($element, ['form-text', 'os2forms-mitid-child-house-nr']); + return $element; + } + +} diff --git a/modules/os2forms_nemid/src/Element/MitidChildKommunekode.php b/modules/os2forms_nemid/src/Element/MitidChildKommunekode.php new file mode 100644 index 00000000..9b773624 --- /dev/null +++ b/modules/os2forms_nemid/src/Element/MitidChildKommunekode.php @@ -0,0 +1,64 @@ + [ + [$class, 'processMitidChildKommunekode'], + [$class, 'processAjaxForm'], + ], + '#element_validate' => [ + [$class, 'validateMitidChildKommunekode'], + ], + '#pre_render' => [ + [$class, 'preRenderMitidChildKommunekode'], + ], + '#theme' => 'input__os2forms_mitid_child_kommunekode', + ]; + } + + /** + * Processes a 'os2forms_mitid_child_kommunekode' element. + */ + public static function processMitidChildKommunekode(&$element, FormStateInterface $form_state, &$complete_form) { + // Here you can add and manipulate your element's properties and callbacks. + return $element; + } + + /** + * Webform element validation handler for #type 'os2forms_mitid_child_kommunekode'. + */ + public static function validateMitidChildKommunekode(&$element, FormStateInterface $form_state, &$complete_form) { + // Here you can add custom validation logic. + } + + /** + * {@inheritdoc} + */ + public static function preRenderMitidChildKommunekode(array $element) { + $element = parent::prerenderNemidElementBase($element); + static::setAttributes($element, ['form-text', 'os2forms-mitid-child-kommunekode']); + return $element; + } + +} diff --git a/modules/os2forms_nemid/src/Element/MitidChildName.php b/modules/os2forms_nemid/src/Element/MitidChildName.php new file mode 100644 index 00000000..4d37838f --- /dev/null +++ b/modules/os2forms_nemid/src/Element/MitidChildName.php @@ -0,0 +1,64 @@ + [ + [$class, 'processMitidChildName'], + [$class, 'processAjaxForm'], + ], + '#element_validate' => [ + [$class, 'validateMitidChildName'], + ], + '#pre_render' => [ + [$class, 'preRenderMitidChildName'], + ], + '#theme' => 'input__os2forms_mitid_child_name', + ]; + } + + /** + * Processes a 'os2forms_mitid_child_name' element. + */ + public static function processMitidChildName(&$element, FormStateInterface $form_state, &$complete_form) { + // Here you can add and manipulate your element's properties and callbacks. + return $element; + } + + /** + * Webform element validation handler for #type 'os2forms_mitid_child_name'. + */ + public static function validateMitidChildName(&$element, FormStateInterface $form_state, &$complete_form) { + // Here you can add custom validation logic. + } + + /** + * {@inheritdoc} + */ + public static function preRenderMitidChildName(array $element) { + $element = parent::prerenderNemidElementBase($element); + static::setAttributes($element, ['form-text', 'os2forms-mitid-child-name']); + return $element; + } + +} diff --git a/modules/os2forms_nemid/src/Element/MitidChildPostalCode.php b/modules/os2forms_nemid/src/Element/MitidChildPostalCode.php new file mode 100644 index 00000000..d78da623 --- /dev/null +++ b/modules/os2forms_nemid/src/Element/MitidChildPostalCode.php @@ -0,0 +1,64 @@ + [ + [$class, 'processMitidChildPostalCode'], + [$class, 'processAjaxForm'], + ], + '#element_validate' => [ + [$class, 'validateMitidChildPostalCode'], + ], + '#pre_render' => [ + [$class, 'preRenderMitidChildPostalCode'], + ], + '#theme' => 'input__os2forms_mitid_child_postal_code', + ]; + } + + /** + * Processes a 'os2forms_mitid_child_postal_code' element. + */ + public static function processMitidChildPostalCode(&$element, FormStateInterface $form_state, &$complete_form) { + // Here you can add and manipulate your element's properties and callbacks. + return $element; + } + + /** + * Webform element validation handler for #type 'os2forms_mitid_child_postal_code'. + */ + public static function validateMitidChildPostalCode(&$element, FormStateInterface $form_state, &$complete_form) { + // Here you can add custom validation logic. + } + + /** + * {@inheritdoc} + */ + public static function preRenderMitidChildPostalCode(array $element) { + $element = parent::prerenderNemidElementBase($element); + static::setAttributes($element, ['form-text', 'os2forms-mitid-child-postal-code']); + return $element; + } + +} diff --git a/modules/os2forms_nemid/src/Element/MitidChildStreet.php b/modules/os2forms_nemid/src/Element/MitidChildStreet.php new file mode 100644 index 00000000..b5f68beb --- /dev/null +++ b/modules/os2forms_nemid/src/Element/MitidChildStreet.php @@ -0,0 +1,64 @@ + [ + [$class, 'processMitidChildStreet'], + [$class, 'processAjaxForm'], + ], + '#element_validate' => [ + [$class, 'validateMitidChildStreet'], + ], + '#pre_render' => [ + [$class, 'preRenderMitidChildStreet'], + ], + '#theme' => 'input__os2forms_mitid_child_street', + ]; + } + + /** + * Processes a 'os2forms_mitid_child_street' element. + */ + public static function processMitidChildStreet(&$element, FormStateInterface $form_state, &$complete_form) { + // Here you can add and manipulate your element's properties and callbacks. + return $element; + } + + /** + * Webform element validation handler for #type 'os2forms_mitid_child_street'. + */ + public static function validateMitidChildStreet(&$element, FormStateInterface $form_state, &$complete_form) { + // Here you can add custom validation logic. + } + + /** + * {@inheritdoc} + */ + public static function preRenderMitidChildStreet(array $element) { + $element = parent::prerenderNemidElementBase($element); + static::setAttributes($element, ['form-text', 'os2forms-mitid-child-street']); + return $element; + } + +} diff --git a/modules/os2forms_nemid/src/Element/MitidChildrenSelectAjaxBehaviour.php b/modules/os2forms_nemid/src/Element/MitidChildrenSelectAjaxBehaviour.php new file mode 100644 index 00000000..9be13c93 --- /dev/null +++ b/modules/os2forms_nemid/src/Element/MitidChildrenSelectAjaxBehaviour.php @@ -0,0 +1,92 @@ +getTriggeringElement(); + $triggerName = $trigger['#name']; + + $childCpr = $form_state->getValue($triggerName); + + /** @var \Drupal\os2web_datalookup\Plugin\DataLookupManager $os2web_datalookup_plugins */ + $os2web_datalookup_plugins = \Drupal::service('plugin.manager.os2web_datalookup'); + + /** @var \Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DataLookupInterfaceCpr $cprPlugin */ + $cprPlugin = $os2web_datalookup_plugins->createDefaultInstanceByGroup('cpr_lookup'); + + if ($cprPlugin->isReady()) { + $cprLookupResult = $cprPlugin->lookup($childCpr); + } + + /** @var \Drupal\webform\WebformSubmissionForm $webformSubmissionForm */ + $webformSubmissionForm = $form_state->getFormObject(); + /** @var \Drupal\webform\WebformSubmissionInterface $webformSubmission */ + $webformSubmission = $webformSubmissionForm->getEntity(); + $webform = $webformSubmission->getWebform(); + $elements = $webform->getElementsDecodedAndFlattened(); + + $response = new AjaxResponse(); + + foreach ($elements as $element) { + if(isset($element['#type'])) { + switch ($element['#type']) { + case 'os2forms_mitid_child_name': + $element['#value'] = $cprLookupResult->getName(); + $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-name', $element)); + break; + case 'os2forms_mitid_child_cpr': + $element['#value'] = $cprLookupResult->getCpr(); + $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-cpr', $element)); + break; + case 'os2forms_mitid_child_address': + $element['#value'] = $cprLookupResult->getAddress(); + $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-address', $element)); + break; + case 'os2forms_mitid_child_apartment_nr': + $element['#value'] = $cprLookupResult->getApartmentNr(); + $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-apartment_nr', $element)); + break; + case 'os2forms_mitid_child_city': + $element['#value'] = $cprLookupResult->getCity(); + $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-city', $element)); + break; + case 'os2forms_mitid_child_coaddress': + $element['#value'] = $cprLookupResult->getCoName(); + $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-coaddress', $element)); + break; + case 'os2forms_mitid_child_floor': + $element['#value'] = $cprLookupResult->getFloor(); + $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-floor', $element)); + break; + case 'os2forms_mitid_child_house_nr': + $element['#value'] = $cprLookupResult->getHouseNr(); + $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-house-nr', $element)); + break; + case 'os2forms_mitid_child_kommunekode': + $element['#value'] = $cprLookupResult->getMunicipalityCode(); + $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-kommunekode', $element)); + break; + case 'os2forms_mitid_child_postal_code': + $element['#value'] = $cprLookupResult->getPostalCode(); + $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-postal-code', $element)); + break; + case 'os2forms_mitid_child_street': + $element['#value'] = $cprLookupResult->getStreet(); + $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-street', $element)); + break; + } + } + } + + return $response; + } +} diff --git a/modules/os2forms_nemid/src/Element/NemidChildrenRadios.php b/modules/os2forms_nemid/src/Element/NemidChildrenRadios.php index 67379784..c6d303b9 100644 --- a/modules/os2forms_nemid/src/Element/NemidChildrenRadios.php +++ b/modules/os2forms_nemid/src/Element/NemidChildrenRadios.php @@ -17,4 +17,19 @@ */ class NemidChildrenRadios extends Radios { + /** + * {@inheritdoc} + */ + public function getInfo() { + return parent::getInfo() + [ + '#ajax' => [ + 'callback' => [MitidChildrenSelectAjaxBehaviour::class, 'mitidChildrenSelectAjax'], + 'event' => 'change', + 'progress' => [ + 'type' => 'throbber', + 'message' => $this->t('Please wait...'), + ], + ], + ]; + } } diff --git a/modules/os2forms_nemid/src/Element/NemidChildrenSelect.php b/modules/os2forms_nemid/src/Element/NemidChildrenSelect.php index 052dd6e1..567021f4 100644 --- a/modules/os2forms_nemid/src/Element/NemidChildrenSelect.php +++ b/modules/os2forms_nemid/src/Element/NemidChildrenSelect.php @@ -17,4 +17,20 @@ */ class NemidChildrenSelect extends Select { + /** + * {@inheritdoc} + */ + public function getInfo() { + return parent::getInfo() + [ + '#ajax' => [ + 'callback' => [MitidChildrenSelectAjaxBehaviour::class, 'mitidChildrenSelectAjax'], + 'event' => 'change', + 'progress' => [ + 'type' => 'throbber', + 'message' => $this->t('Please wait...'), + ], + ], + ]; + } + } diff --git a/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildAddress.php b/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildAddress.php new file mode 100644 index 00000000..ace06e71 --- /dev/null +++ b/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildAddress.php @@ -0,0 +1,19 @@ + '', + 'size' => '', + 'minlength' => '', + 'maxlength' => '', + 'placeholder' => '', + 'readonly' => '', + ]; + + return $properties; + } + + /** + * {@inheritdoc} + */ + public function form(array $form, FormStateInterface $form_state) { + $form = parent::form($form, $form_state); + + // @see \Drupal\webform\Plugin\WebformElement\WebformEntityReferenceTrait::form + $element_properties = $form_state->get('element_properties'); + // If element is new, set readonly by default. + if (empty($element_properties['title'])) { + $form['form']['readonly']['#value'] = TRUE; + } + + // Here you can define and alter a webform element's properties UI. + // Form element property visibility and default values are defined via + // ::getDefaultProperties. + // + // @see \Drupal\webform\Plugin\WebformElementBase::form + // @see \Drupal\webform\Plugin\WebformElement\TextBase::form + return $form; + } + +} diff --git a/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildFloor.php b/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildFloor.php new file mode 100644 index 00000000..ec8371b6 --- /dev/null +++ b/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildFloor.php @@ -0,0 +1,19 @@ + '', 'options' => [], ] + parent::defineDefaultProperties(); return $properties; @@ -41,14 +40,6 @@ public function form(array $form, FormStateInterface $form_state) { $form['options']['options']['#required'] = FALSE; $form['options']['#access'] = FALSE; - $form['element']['cpr_output_type'] = [ - '#type' => 'radios', - '#options' => ['cpr' => $this->t('CPR'), 'name' => $this->t('Name')], - '#title' => $this - ->t('CPR output type'), - '#required' => TRUE, - ]; - return $form; } @@ -141,12 +132,7 @@ public function handleElementPrepopulate(array &$element, FormStateInterface &$f if ($children = $cprLookupResult->getFieldValue($prepopulateKey)) { if (is_array($children) && !empty($children)) { foreach ($children as $child) { - if ($element['#cpr_output_type'] == 'cpr') { - $options[$child['cpr']] = $child['name']; - } - else { - $options[$child['name']] = $child['name']; - } + $options[$child['cpr']] = $child['name']; } } } diff --git a/modules/os2forms_nemid/src/Plugin/WebformElement/NemidChildrenSelect.php b/modules/os2forms_nemid/src/Plugin/WebformElement/NemidChildrenSelect.php index ec8ddefc..d2eec470 100644 --- a/modules/os2forms_nemid/src/Plugin/WebformElement/NemidChildrenSelect.php +++ b/modules/os2forms_nemid/src/Plugin/WebformElement/NemidChildrenSelect.php @@ -12,8 +12,8 @@ * * @WebformElement( * id = "os2forms_nemid_children_select", - * label = @Translation("NemID Children Select"), - * description = @Translation("Provides a NemID Children select element."), + * label = @Translation("MitID Children Select"), + * description = @Translation("Provides a MitID Children select element."), * category = @Translation("NemID"), * ) * @@ -27,7 +27,6 @@ class NemidChildrenSelect extends Select implements NemidElementPersonalInterfac */ protected function defineDefaultProperties() { $properties = [ - 'cpr_output_type' => '', 'options' => [], ] + parent::defineDefaultProperties(); return $properties; @@ -41,14 +40,6 @@ public function form(array $form, FormStateInterface $form_state) { $form['options']['options']['#required'] = FALSE; $form['options']['#access'] = FALSE; - $form['element']['cpr_output_type'] = [ - '#type' => 'radios', - '#options' => ['cpr' => $this->t('CPR'), 'name' => $this->t('Name')], - '#title' => $this - ->t('CPR output type'), - '#required' => TRUE, - ]; - return $form; } @@ -141,12 +132,7 @@ public function handleElementPrepopulate(array &$element, FormStateInterface &$f if ($children = $cprLookupResult->getFieldValue($prepopulateKey)) { if (is_array($children) && !empty($children)) { foreach ($children as $child) { - if ($element['#cpr_output_type'] == 'cpr') { - $options[$child['cpr']] = $child['name']; - } - else { - $options[$child['name']] = $child['name']; - } + $options[$child['cpr']] = $child['name']; } } } diff --git a/modules/os2forms_nemid/src/Service/FormsHelper.php b/modules/os2forms_nemid/src/Service/FormsHelper.php index e271d552..f1fecd60 100644 --- a/modules/os2forms_nemid/src/Service/FormsHelper.php +++ b/modules/os2forms_nemid/src/Service/FormsHelper.php @@ -102,7 +102,7 @@ public function retrieveCprLookupResult(FormStateInterface $form_state) { * * @throws \Drupal\Component\Plugin\Exception\PluginException */ - private function lookupPersonData(FormStateInterface $form_state) { + public function lookupPersonData(FormStateInterface $form_state) { $cprResult = new CprLookupResult(); $cpr = NULL; From 5518d4c4852fb125be32956b7a963a66d3070743 Mon Sep 17 00:00:00 2001 From: Stanislav Kutasevits Date: Fri, 12 Jan 2024 13:16:52 +0200 Subject: [PATCH 02/15] S2FRMS-40 - Adding name&address protection text, fixing populate --- .../MitidChildrenSelectAjaxBehaviour.php | 40 +++++++++++++++++-- .../src/Plugin/WebformElement/NemidCpr.php | 7 ++++ .../ServiceplatformenCprElementBase.php | 19 +++++++++ 3 files changed, 63 insertions(+), 3 deletions(-) diff --git a/modules/os2forms_nemid/src/Element/MitidChildrenSelectAjaxBehaviour.php b/modules/os2forms_nemid/src/Element/MitidChildrenSelectAjaxBehaviour.php index 9be13c93..bd826051 100644 --- a/modules/os2forms_nemid/src/Element/MitidChildrenSelectAjaxBehaviour.php +++ b/modules/os2forms_nemid/src/Element/MitidChildrenSelectAjaxBehaviour.php @@ -2,6 +2,7 @@ namespace Drupal\os2forms_nemid\Element; +use Drupal\Component\Utility\NestedArray; use Drupal\Core\Ajax\AjaxResponse; use Drupal\Core\Ajax\ReplaceCommand; use Drupal\Core\Form\FormStateInterface; @@ -32,15 +33,21 @@ public static function mitidChildrenSelectAjax(array &$form, FormStateInterface /** @var \Drupal\webform\WebformSubmissionInterface $webformSubmission */ $webformSubmission = $webformSubmissionForm->getEntity(); $webform = $webformSubmission->getWebform(); - $elements = $webform->getElementsDecodedAndFlattened(); + $elementsFlattened = $webform->getElementsInitializedAndFlattened(); $response = new AjaxResponse(); - foreach ($elements as $element) { - if(isset($element['#type'])) { + foreach ($elementsFlattened as $flattenedElement) { + if (isset($flattenedElement['#type'])) { + $parents = $flattenedElement['#webform_parents']; + $element = NestedArray::getValue($form['elements'], $parents); + switch ($element['#type']) { case 'os2forms_mitid_child_name': $element['#value'] = $cprLookupResult->getName(); + if (!empty($element['#value'])) { + $element['#value'] .= $cprLookupResult->isNameAddressProtected() ? ' (Navne- og adressebeskyttelse)' : ''; + } $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-name', $element)); break; case 'os2forms_mitid_child_cpr': @@ -49,38 +56,65 @@ public static function mitidChildrenSelectAjax(array &$form, FormStateInterface break; case 'os2forms_mitid_child_address': $element['#value'] = $cprLookupResult->getAddress(); + if (!empty($element['#value'])) { + $element['#value'] .= $cprLookupResult->isNameAddressProtected() ? ' (Navne- og adressebeskyttelse)' : ''; + } $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-address', $element)); break; case 'os2forms_mitid_child_apartment_nr': $element['#value'] = $cprLookupResult->getApartmentNr(); + if (!empty($element['#value'])) { + $element['#value'] .= $cprLookupResult->isNameAddressProtected() ? ' (Navne- og adressebeskyttelse)' : ''; + } $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-apartment_nr', $element)); break; case 'os2forms_mitid_child_city': $element['#value'] = $cprLookupResult->getCity(); + if (!empty($element['#value'])) { + $element['#value'] .= $cprLookupResult->isNameAddressProtected() ? ' (Navne- og adressebeskyttelse)' : ''; + } $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-city', $element)); break; case 'os2forms_mitid_child_coaddress': $element['#value'] = $cprLookupResult->getCoName(); + if (!empty($element['#value'])) { + $element['#value'] .= $cprLookupResult->isNameAddressProtected() ? ' (Navne- og adressebeskyttelse)' : ''; + } $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-coaddress', $element)); break; case 'os2forms_mitid_child_floor': $element['#value'] = $cprLookupResult->getFloor(); + if (!empty($element['#value'])) { + $element['#value'] .= $cprLookupResult->isNameAddressProtected() ? ' (Navne- og adressebeskyttelse)' : ''; + } $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-floor', $element)); break; case 'os2forms_mitid_child_house_nr': $element['#value'] = $cprLookupResult->getHouseNr(); + if (!empty($element['#value'])) { + $element['#value'] .= $cprLookupResult->isNameAddressProtected() ? ' (Navne- og adressebeskyttelse)' : ''; + } $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-house-nr', $element)); break; case 'os2forms_mitid_child_kommunekode': $element['#value'] = $cprLookupResult->getMunicipalityCode(); + if (!empty($element['#value'])) { + $element['#value'] .= $cprLookupResult->isNameAddressProtected() ? ' (Navne- og adressebeskyttelse)' : ''; + } $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-kommunekode', $element)); break; case 'os2forms_mitid_child_postal_code': $element['#value'] = $cprLookupResult->getPostalCode(); + if (!empty($element['#value'])) { + $element['#value'] .= $cprLookupResult->isNameAddressProtected() ? ' (Navne- og adressebeskyttelse)' : ''; + } $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-postal-code', $element)); break; case 'os2forms_mitid_child_street': $element['#value'] = $cprLookupResult->getStreet(); + if (!empty($element['#value'])) { + $element['#value'] .= $cprLookupResult->isNameAddressProtected() ? ' (Navne- og adressebeskyttelse)' : ''; + } $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-street', $element)); break; } diff --git a/modules/os2forms_nemid/src/Plugin/WebformElement/NemidCpr.php b/modules/os2forms_nemid/src/Plugin/WebformElement/NemidCpr.php index 03a27154..9abd1f9e 100644 --- a/modules/os2forms_nemid/src/Plugin/WebformElement/NemidCpr.php +++ b/modules/os2forms_nemid/src/Plugin/WebformElement/NemidCpr.php @@ -26,4 +26,11 @@ public function getPrepopulateFieldFieldKey(array &$element) { return CprLookupResult::CPR; } + /** + * {@inheritdoc} + */ + public function appendNameAddressProtectedText(CprLookupResult $cprLookupResult) { + return ''; + } + } diff --git a/modules/os2forms_nemid/src/Plugin/WebformElement/ServiceplatformenCprElementBase.php b/modules/os2forms_nemid/src/Plugin/WebformElement/ServiceplatformenCprElementBase.php index 9338107d..34f48522 100644 --- a/modules/os2forms_nemid/src/Plugin/WebformElement/ServiceplatformenCprElementBase.php +++ b/modules/os2forms_nemid/src/Plugin/WebformElement/ServiceplatformenCprElementBase.php @@ -3,6 +3,7 @@ namespace Drupal\os2forms_nemid\Plugin\WebformElement; use Drupal\Core\Form\FormStateInterface; +use Drupal\os2web_datalookup\LookupResult\CprLookupResult; /** * Provides a abstract ServicePlatformenCpr Element. @@ -27,8 +28,26 @@ public function handleElementPrepopulate(array &$element, FormStateInterface &$f $prepopulateKey = $this->getPrepopulateFieldFieldKey($element); if ($value = $cprLookupResult->getFieldValue($prepopulateKey)) { $element['#value'] = $value; + + // Appending name and address protection. + if (!empty($value)) { + $element['#value'] .= $this->appendNameAddressProtectedText($cprLookupResult); + } } } } + /** + * Appends name and address protected text, if person has name/address protection. + * + * @param CprLookupResult $cprLookupResult + * Initialized CprLooupResult. + * + * @return string + * String " (Navne- og adressebeskyttelse)" or nothing. + */ + public function appendNameAddressProtectedText(CprLookupResult $cprLookupResult) { + return $cprLookupResult->isNameAddressProtected() ? ' (Navne- og adressebeskyttelse)' : ''; + } + } From d8ade8b854693850336c5c4af499f837e26adda7 Mon Sep 17 00:00:00 2001 From: Stanislav Kutasevits Date: Tue, 16 Jan 2024 13:52:12 +0200 Subject: [PATCH 03/15] S2FRMS-40 - child select - name address protection --- .../src/Plugin/WebformElement/NemidChildrenRadios.php | 2 +- .../src/Plugin/WebformElement/NemidChildrenSelect.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/os2forms_nemid/src/Plugin/WebformElement/NemidChildrenRadios.php b/modules/os2forms_nemid/src/Plugin/WebformElement/NemidChildrenRadios.php index 05bbedea..d871a11d 100644 --- a/modules/os2forms_nemid/src/Plugin/WebformElement/NemidChildrenRadios.php +++ b/modules/os2forms_nemid/src/Plugin/WebformElement/NemidChildrenRadios.php @@ -132,7 +132,7 @@ public function handleElementPrepopulate(array &$element, FormStateInterface &$f if ($children = $cprLookupResult->getFieldValue($prepopulateKey)) { if (is_array($children) && !empty($children)) { foreach ($children as $child) { - $options[$child['cpr']] = $child['name']; + $options[$child['cpr']] = $child['name'] . ($child['nameAddressProtected'] ? ' (Navne- og adressebeskyttelse)' : '') ; } } } diff --git a/modules/os2forms_nemid/src/Plugin/WebformElement/NemidChildrenSelect.php b/modules/os2forms_nemid/src/Plugin/WebformElement/NemidChildrenSelect.php index d2eec470..eab8106e 100644 --- a/modules/os2forms_nemid/src/Plugin/WebformElement/NemidChildrenSelect.php +++ b/modules/os2forms_nemid/src/Plugin/WebformElement/NemidChildrenSelect.php @@ -132,7 +132,7 @@ public function handleElementPrepopulate(array &$element, FormStateInterface &$f if ($children = $cprLookupResult->getFieldValue($prepopulateKey)) { if (is_array($children) && !empty($children)) { foreach ($children as $child) { - $options[$child['cpr']] = $child['name']; + $options[$child['cpr']] = $child['name'] . ($child['nameAddressProtected'] ? ' (Navne- og adressebeskyttelse)' : '') ; } } } From bff89d673e53ca8c56a8f78a7c622954f4d73108 Mon Sep 17 00:00:00 2001 From: Stanislav Kutasevits Date: Sat, 20 Jan 2024 16:47:43 +0200 Subject: [PATCH 04/15] S2FRMS-40 - Adding other guardian element --- .../WebformHandler/WebformHandlerSF1601.php | 2 + .../src/Element/MitidChildOtherGuardian.php | 65 +++++++ .../MitidChildrenSelectAjaxBehaviour.php | 168 +++++++++--------- .../MitidChildOtherGuardian.php | 19 ++ .../src/Service/FormsHelper.php | 21 +++ 5 files changed, 187 insertions(+), 88 deletions(-) create mode 100644 modules/os2forms_nemid/src/Element/MitidChildOtherGuardian.php create mode 100644 modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildOtherGuardian.php diff --git a/modules/os2forms_digital_post/src/Plugin/WebformHandler/WebformHandlerSF1601.php b/modules/os2forms_digital_post/src/Plugin/WebformHandler/WebformHandlerSF1601.php index 667368db..9da57179 100644 --- a/modules/os2forms_digital_post/src/Plugin/WebformHandler/WebformHandlerSF1601.php +++ b/modules/os2forms_digital_post/src/Plugin/WebformHandler/WebformHandlerSF1601.php @@ -217,12 +217,14 @@ private function getRecipientElements(): array { 'os2forms_nemid_company_cvr_fetch_data', 'os2forms_nemid_cpr', 'os2forms_person_lookup', + 'os2forms_mitid_child_other_guardian', // @todo Remove these when we remove the elements. 'cpr_element', 'cpr_value_element', 'cvr_element', 'cvr_value_element', ]; + $elements = array_filter( $elements, static function (array $element) use ($elementTypes) { diff --git a/modules/os2forms_nemid/src/Element/MitidChildOtherGuardian.php b/modules/os2forms_nemid/src/Element/MitidChildOtherGuardian.php new file mode 100644 index 00000000..faa8f386 --- /dev/null +++ b/modules/os2forms_nemid/src/Element/MitidChildOtherGuardian.php @@ -0,0 +1,65 @@ + [ + [$class, 'processMitidChildOtherGuardian'], + [$class, 'processAjaxForm'], + ], + '#element_validate' => [ + [$class, 'validateMitidChildOtherGuardian'], + ], + '#pre_render' => [ + [$class, 'preRenderMitidChildOtherGuardian'], + ], + '#theme' => 'input__os2forms_mitid_child_other_guardian', + ]; + } + + /** + * Processes a 'os2forms_mitid_child_other_guardian' element. + */ + public static function processMitidChildOtherGuardian(&$element, FormStateInterface $form_state, &$complete_form) { + // Here you can add and manipulate your element's properties and callbacks. + return $element; + } + + /** + * Webform element validation handler for #type 'os2forms_mitid_child_other_guardian'. + */ + public static function validateMitidChildOtherGuardian(&$element, FormStateInterface $form_state, &$complete_form) { + // Here you can add custom validation logic. + } + + /** + * {@inheritdoc} + */ + public static function preRenderMitidChildOtherGuardian(array $element) { + $element = parent::preRenderHidden($element); + static::setAttributes($element, ['os2forms-mitid-child-other-guardian']); + return $element; + } + +} diff --git a/modules/os2forms_nemid/src/Element/MitidChildrenSelectAjaxBehaviour.php b/modules/os2forms_nemid/src/Element/MitidChildrenSelectAjaxBehaviour.php index bd826051..985593a6 100644 --- a/modules/os2forms_nemid/src/Element/MitidChildrenSelectAjaxBehaviour.php +++ b/modules/os2forms_nemid/src/Element/MitidChildrenSelectAjaxBehaviour.php @@ -6,6 +6,7 @@ use Drupal\Core\Ajax\AjaxResponse; use Drupal\Core\Ajax\ReplaceCommand; use Drupal\Core\Form\FormStateInterface; +use Drupal\os2forms_nemid\Service\FormsHelper; /** * Provides a children select ajax behaviour for MitidChildrenSelect and MitidChildrenRadios. @@ -13,9 +14,11 @@ class MitidChildrenSelectAjaxBehaviour { public static function mitidChildrenSelectAjax(array &$form, FormStateInterface $form_state) { + $response = new AjaxResponse(); + + // Getting child CPR. $trigger = $form_state->getTriggeringElement(); $triggerName = $trigger['#name']; - $childCpr = $form_state->getValue($triggerName); /** @var \Drupal\os2web_datalookup\Plugin\DataLookupManager $os2web_datalookup_plugins */ @@ -26,97 +29,86 @@ public static function mitidChildrenSelectAjax(array &$form, FormStateInterface if ($cprPlugin->isReady()) { $cprLookupResult = $cprPlugin->lookup($childCpr); - } - /** @var \Drupal\webform\WebformSubmissionForm $webformSubmissionForm */ - $webformSubmissionForm = $form_state->getFormObject(); - /** @var \Drupal\webform\WebformSubmissionInterface $webformSubmission */ - $webformSubmission = $webformSubmissionForm->getEntity(); - $webform = $webformSubmission->getWebform(); - $elementsFlattened = $webform->getElementsInitializedAndFlattened(); + /** @var \Drupal\webform\WebformSubmissionForm $webformSubmissionForm */ + $webformSubmissionForm = $form_state->getFormObject(); + /** @var \Drupal\webform\WebformSubmissionInterface $webformSubmission */ + $webformSubmission = $webformSubmissionForm->getEntity(); + $webform = $webformSubmission->getWebform(); + $elementsFlattened = $webform->getElementsInitializedAndFlattened(); - $response = new AjaxResponse(); + foreach ($elementsFlattened as $flattenedElement) { + if (isset($flattenedElement['#type'])) { + $parents = $flattenedElement['#webform_parents']; + $element = NestedArray::getValue($form['elements'], $parents); + + switch ($element['#type']) { + case 'os2forms_mitid_child_name': + $element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getName() : 'Navne- og adressebeskyttet'; + $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-name', $element)); + break; + case 'os2forms_mitid_child_cpr': + $element['#value'] = $cprLookupResult->getCpr(); + $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-cpr', $element)); + break; + case 'os2forms_mitid_child_address': + $element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getAddress() : 'Navne- og adressebeskyttet'; + $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-address', $element)); + break; + case 'os2forms_mitid_child_apartment_nr': + $element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getApartmentNr() : 'Navne- og adressebeskyttet'; + $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-apartment_nr', $element)); + break; + case 'os2forms_mitid_child_city': + $element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getCity() : 'Navne- og adressebeskyttet'; + $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-city', $element)); + break; + case 'os2forms_mitid_child_coaddress': + $element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getCoName() : 'Navne- og adressebeskyttet'; + $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-coaddress', $element)); + break; + case 'os2forms_mitid_child_floor': + $element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getFloor() : 'Navne- og adressebeskyttet'; + $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-floor', $element)); + break; + case 'os2forms_mitid_child_house_nr': + $element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getHouseNr() : 'Navne- og adressebeskyttet'; + $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-house-nr', $element)); + break; + case 'os2forms_mitid_child_kommunekode': + $element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getMunicipalityCode() : 'Navne- og adressebeskyttet'; + $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-kommunekode', $element)); + break; + case 'os2forms_mitid_child_postal_code': + $element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getPostalCode() : 'Navne- og adressebeskyttet'; + $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-postal-code', $element)); + break; + case 'os2forms_mitid_child_street': + $element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getStreet() : 'Navne- og adressebeskyttet'; + $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-street', $element)); + break; + case 'os2forms_mitid_child_other_guardian': + $otherGuardianCpr = NULL; + $allGuardians = $cprLookupResult->getGuardians(); + + if (!empty($allGuardians)) { + // Making a guess primary CPR is saved in the form state. + $primaryCprLookupResult = FormsHelper::retrieveCachedCprLookupResult($form_state); - foreach ($elementsFlattened as $flattenedElement) { - if (isset($flattenedElement['#type'])) { - $parents = $flattenedElement['#webform_parents']; - $element = NestedArray::getValue($form['elements'], $parents); + if ($primaryCprLookupResult) { + foreach ($allGuardians as $guardian) { + // Find other CPR number. + if ($guardian['cpr'] != $primaryCprLookupResult->getCpr()) { + $otherGuardianCpr = $guardian['cpr']; + } + } + } + } - switch ($element['#type']) { - case 'os2forms_mitid_child_name': - $element['#value'] = $cprLookupResult->getName(); - if (!empty($element['#value'])) { - $element['#value'] .= $cprLookupResult->isNameAddressProtected() ? ' (Navne- og adressebeskyttelse)' : ''; - } - $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-name', $element)); - break; - case 'os2forms_mitid_child_cpr': - $element['#value'] = $cprLookupResult->getCpr(); - $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-cpr', $element)); - break; - case 'os2forms_mitid_child_address': - $element['#value'] = $cprLookupResult->getAddress(); - if (!empty($element['#value'])) { - $element['#value'] .= $cprLookupResult->isNameAddressProtected() ? ' (Navne- og adressebeskyttelse)' : ''; - } - $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-address', $element)); - break; - case 'os2forms_mitid_child_apartment_nr': - $element['#value'] = $cprLookupResult->getApartmentNr(); - if (!empty($element['#value'])) { - $element['#value'] .= $cprLookupResult->isNameAddressProtected() ? ' (Navne- og adressebeskyttelse)' : ''; - } - $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-apartment_nr', $element)); - break; - case 'os2forms_mitid_child_city': - $element['#value'] = $cprLookupResult->getCity(); - if (!empty($element['#value'])) { - $element['#value'] .= $cprLookupResult->isNameAddressProtected() ? ' (Navne- og adressebeskyttelse)' : ''; - } - $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-city', $element)); - break; - case 'os2forms_mitid_child_coaddress': - $element['#value'] = $cprLookupResult->getCoName(); - if (!empty($element['#value'])) { - $element['#value'] .= $cprLookupResult->isNameAddressProtected() ? ' (Navne- og adressebeskyttelse)' : ''; - } - $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-coaddress', $element)); - break; - case 'os2forms_mitid_child_floor': - $element['#value'] = $cprLookupResult->getFloor(); - if (!empty($element['#value'])) { - $element['#value'] .= $cprLookupResult->isNameAddressProtected() ? ' (Navne- og adressebeskyttelse)' : ''; - } - $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-floor', $element)); - break; - case 'os2forms_mitid_child_house_nr': - $element['#value'] = $cprLookupResult->getHouseNr(); - if (!empty($element['#value'])) { - $element['#value'] .= $cprLookupResult->isNameAddressProtected() ? ' (Navne- og adressebeskyttelse)' : ''; - } - $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-house-nr', $element)); - break; - case 'os2forms_mitid_child_kommunekode': - $element['#value'] = $cprLookupResult->getMunicipalityCode(); - if (!empty($element['#value'])) { - $element['#value'] .= $cprLookupResult->isNameAddressProtected() ? ' (Navne- og adressebeskyttelse)' : ''; - } - $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-kommunekode', $element)); - break; - case 'os2forms_mitid_child_postal_code': - $element['#value'] = $cprLookupResult->getPostalCode(); - if (!empty($element['#value'])) { - $element['#value'] .= $cprLookupResult->isNameAddressProtected() ? ' (Navne- og adressebeskyttelse)' : ''; - } - $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-postal-code', $element)); - break; - case 'os2forms_mitid_child_street': - $element['#value'] = $cprLookupResult->getStreet(); - if (!empty($element['#value'])) { - $element['#value'] .= $cprLookupResult->isNameAddressProtected() ? ' (Navne- og adressebeskyttelse)' : ''; - } - $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-street', $element)); - break; + $element['#value'] = $otherGuardianCpr; + $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-other-guardian', $element)); + break; + } } } } diff --git a/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildOtherGuardian.php b/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildOtherGuardian.php new file mode 100644 index 00000000..f641e784 --- /dev/null +++ b/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildOtherGuardian.php @@ -0,0 +1,19 @@ +has('cprLookupResult')) { + $cprLookupResult = $form_state->get('cprLookupResult'); + } + + return $cprLookupResult; + } + /** * Performs lookup of person data. * From ed022f9a27fbb86f3f64c6b8374450cb7d7e722f Mon Sep 17 00:00:00 2001 From: Stanislav Kutasevits Date: Fri, 26 Jan 2024 11:14:23 +0200 Subject: [PATCH 05/15] S2FRMS-40 other guardian CPR fix --- .../src/Element/MitidChildOtherGuardian.php | 40 ++++++++----------- .../src/Element/NemidChildrenRadios.php | 1 + .../WebformElement/NemidChildrenRadios.php | 21 +++++++++- .../WebformElement/NemidChildrenSelect.php | 21 +++++++++- .../ServiceplatformenCprElementBase.php | 4 +- 5 files changed, 59 insertions(+), 28 deletions(-) diff --git a/modules/os2forms_nemid/src/Element/MitidChildOtherGuardian.php b/modules/os2forms_nemid/src/Element/MitidChildOtherGuardian.php index faa8f386..31e99f9c 100644 --- a/modules/os2forms_nemid/src/Element/MitidChildOtherGuardian.php +++ b/modules/os2forms_nemid/src/Element/MitidChildOtherGuardian.php @@ -8,13 +8,12 @@ /** * Provides a 'os2forms_mitid_child_other_guardian'. * - * @FormElement("os2forms_mitid_child_ther_guardian") + * @FormElement("os2forms_mitid_child_other_guardian") * * @see \Drupal\Core\Render\Element\FormElement * @see https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21Element%21FormElement.php/class/FormElement * @see \Drupal\Core\Render\Element\RenderElement * @see https://api.drupal.org/api/drupal/namespace/Drupal%21Core%21Render%21Element - * @see \Drupal\os2forms_nemid\Element\NemidCpr */ class MitidChildOtherGuardian extends Hidden { @@ -22,28 +21,20 @@ class MitidChildOtherGuardian extends Hidden { * {@inheritdoc} */ public function getInfo() { - $class = get_class($this); - return parent::getInfo() + [ - '#process' => [ - [$class, 'processMitidChildOtherGuardian'], - [$class, 'processAjaxForm'], - ], - '#element_validate' => [ - [$class, 'validateMitidChildOtherGuardian'], - ], - '#pre_render' => [ - [$class, 'preRenderMitidChildOtherGuardian'], - ], - '#theme' => 'input__os2forms_mitid_child_other_guardian', + $class = static::class; + + $parentInfo = parent::getInfo() + [ + '#element_validate' => [ + [$class, 'validateMitidChildOtherGuardian'], + ], + ]; + + // Adding custom #pre_render. + $parentInfo['#pre_render'] = [ + [$class, 'preRenderMitidChildOtherGuardian'] ]; - } - /** - * Processes a 'os2forms_mitid_child_other_guardian' element. - */ - public static function processMitidChildOtherGuardian(&$element, FormStateInterface $form_state, &$complete_form) { - // Here you can add and manipulate your element's properties and callbacks. - return $element; + return $parentInfo; } /** @@ -56,9 +47,10 @@ public static function validateMitidChildOtherGuardian(&$element, FormStateInter /** * {@inheritdoc} */ - public static function preRenderMitidChildOtherGuardian(array $element) { + public static function preRenderMitidChildOtherGuardian($element) { $element = parent::preRenderHidden($element); - static::setAttributes($element, ['os2forms-mitid-child-other-guardian']); + static::setAttributes($element, ['os2forms-mitid-child-other-guardian', 'js-form-type-os2forms-mitid-child-other-guardian']); + return $element; } diff --git a/modules/os2forms_nemid/src/Element/NemidChildrenRadios.php b/modules/os2forms_nemid/src/Element/NemidChildrenRadios.php index c6d303b9..bf188756 100644 --- a/modules/os2forms_nemid/src/Element/NemidChildrenRadios.php +++ b/modules/os2forms_nemid/src/Element/NemidChildrenRadios.php @@ -2,6 +2,7 @@ namespace Drupal\os2forms_nemid\Element; +use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Element\Radios; /** diff --git a/modules/os2forms_nemid/src/Plugin/WebformElement/NemidChildrenRadios.php b/modules/os2forms_nemid/src/Plugin/WebformElement/NemidChildrenRadios.php index d871a11d..688c6435 100644 --- a/modules/os2forms_nemid/src/Plugin/WebformElement/NemidChildrenRadios.php +++ b/modules/os2forms_nemid/src/Plugin/WebformElement/NemidChildrenRadios.php @@ -28,6 +28,7 @@ class NemidChildrenRadios extends Radios implements NemidElementPersonalInterfac protected function defineDefaultProperties() { $properties = [ 'options' => [], + 'address_protection_help_text' => '', ] + parent::defineDefaultProperties(); return $properties; } @@ -40,6 +41,12 @@ public function form(array $form, FormStateInterface $form_state) { $form['options']['options']['#required'] = FALSE; $form['options']['#access'] = FALSE; + $form['element_description']['address_protection_help_text'] = [ + '#type' => 'webform_html_editor', + '#title' => $this->t('Address protection help text'), + '#description' => $this->t('Address protection help text is shown if any of the children has address and name protection active'), + ]; + return $form; } @@ -127,18 +134,30 @@ public function handleElementPrepopulate(array &$element, FormStateInterface &$f $options = []; + $showAddressNameProtectionMessage = FALSE; + if ($cprLookupResult) { $prepopulateKey = $this->getPrepopulateFieldFieldKey($element); if ($children = $cprLookupResult->getFieldValue($prepopulateKey)) { if (is_array($children) && !empty($children)) { foreach ($children as $child) { - $options[$child['cpr']] = $child['name'] . ($child['nameAddressProtected'] ? ' (Navne- og adressebeskyttelse)' : '') ; + if ($child['nameAddressProtected']) { + $options[$child['cpr']] = $child['cpr'] . ' (Navne- og adressebeskyttet)'; + $showAddressNameProtectionMessage = TRUE; + } + else { + $options[$child['cpr']] = $child['name']; + } } } } } $element['#options'] = $options; + + if ($showAddressNameProtectionMessage) { + $element['#suffix'] = $element['#address_protection_help_text']; + } } } diff --git a/modules/os2forms_nemid/src/Plugin/WebformElement/NemidChildrenSelect.php b/modules/os2forms_nemid/src/Plugin/WebformElement/NemidChildrenSelect.php index eab8106e..b49cc3f4 100644 --- a/modules/os2forms_nemid/src/Plugin/WebformElement/NemidChildrenSelect.php +++ b/modules/os2forms_nemid/src/Plugin/WebformElement/NemidChildrenSelect.php @@ -28,6 +28,7 @@ class NemidChildrenSelect extends Select implements NemidElementPersonalInterfac protected function defineDefaultProperties() { $properties = [ 'options' => [], + 'address_protection_help_text' => '', ] + parent::defineDefaultProperties(); return $properties; } @@ -40,6 +41,12 @@ public function form(array $form, FormStateInterface $form_state) { $form['options']['options']['#required'] = FALSE; $form['options']['#access'] = FALSE; + $form['element_description']['address_protection_help_text'] = [ + '#type' => 'webform_html_editor', + '#title' => $this->t('Address protection help text'), + '#description' => $this->t('Address protection help text is shown if any of the children has address and name protection active'), + ]; + return $form; } @@ -127,18 +134,30 @@ public function handleElementPrepopulate(array &$element, FormStateInterface &$f $options = []; + $showAddressNameProtectionMessage = FALSE; + if ($cprLookupResult) { $prepopulateKey = $this->getPrepopulateFieldFieldKey($element); if ($children = $cprLookupResult->getFieldValue($prepopulateKey)) { if (is_array($children) && !empty($children)) { foreach ($children as $child) { - $options[$child['cpr']] = $child['name'] . ($child['nameAddressProtected'] ? ' (Navne- og adressebeskyttelse)' : '') ; + if ($child['nameAddressProtected']) { + $options[$child['cpr']] = $child['cpr'] . ' (Navne- og adressebeskyttet)'; + $showAddressNameProtectionMessage = TRUE; + } + else { + $options[$child['cpr']] = $child['name']; + } } } } } $element['#options'] = $options; + + if ($showAddressNameProtectionMessage) { + $element['#suffix'] = $element['#address_protection_help_text']; + } } } diff --git a/modules/os2forms_nemid/src/Plugin/WebformElement/ServiceplatformenCprElementBase.php b/modules/os2forms_nemid/src/Plugin/WebformElement/ServiceplatformenCprElementBase.php index 34f48522..6567c6e3 100644 --- a/modules/os2forms_nemid/src/Plugin/WebformElement/ServiceplatformenCprElementBase.php +++ b/modules/os2forms_nemid/src/Plugin/WebformElement/ServiceplatformenCprElementBase.php @@ -44,10 +44,10 @@ public function handleElementPrepopulate(array &$element, FormStateInterface &$f * Initialized CprLooupResult. * * @return string - * String " (Navne- og adressebeskyttelse)" or nothing. + * String " (Navne- og adressebeskyttet)" or nothing. */ public function appendNameAddressProtectedText(CprLookupResult $cprLookupResult) { - return $cprLookupResult->isNameAddressProtected() ? ' (Navne- og adressebeskyttelse)' : ''; + return $cprLookupResult->isNameAddressProtected() ? ' (Navne- og adressebeskyttet)' : ''; } } From 936813b012515f1daf23953827b295c732c70eb2 Mon Sep 17 00:00:00 2001 From: Stanislav Kutasevits Date: Wed, 31 Jan 2024 13:33:14 +0200 Subject: [PATCH 06/15] S2FRMS-40 making other guardian CPR private --- .../MitidChildrenSelectAjaxBehaviour.php | 2 +- .../WebformElement/MitidChildOtherGuardian.php | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/modules/os2forms_nemid/src/Element/MitidChildrenSelectAjaxBehaviour.php b/modules/os2forms_nemid/src/Element/MitidChildrenSelectAjaxBehaviour.php index 985593a6..31570084 100644 --- a/modules/os2forms_nemid/src/Element/MitidChildrenSelectAjaxBehaviour.php +++ b/modules/os2forms_nemid/src/Element/MitidChildrenSelectAjaxBehaviour.php @@ -57,7 +57,7 @@ public static function mitidChildrenSelectAjax(array &$form, FormStateInterface break; case 'os2forms_mitid_child_apartment_nr': $element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getApartmentNr() : 'Navne- og adressebeskyttet'; - $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-apartment_nr', $element)); + $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-apartment-nr', $element)); break; case 'os2forms_mitid_child_city': $element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getCity() : 'Navne- og adressebeskyttet'; diff --git a/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildOtherGuardian.php b/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildOtherGuardian.php index f641e784..f519de48 100644 --- a/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildOtherGuardian.php +++ b/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildOtherGuardian.php @@ -2,6 +2,7 @@ namespace Drupal\os2forms_nemid\Plugin\WebformElement; +use Drupal\Core\Form\FormStateInterface; use Drupal\webform\Plugin\WebformElement\Hidden; /** @@ -16,4 +17,20 @@ */ class MitidChildOtherGuardian extends Hidden { + /** + * {@inheritdoc} + */ + public function form(array $form, FormStateInterface $form_state) { + $form = parent::form($form, $form_state); + + // @see \Drupal\webform\Plugin\WebformElement\WebformEntityReferenceTrait::form + $element_properties = $form_state->get('element_properties'); + + // If element is new, set private by default. + if (empty($element_properties['title'])) { + $form['admin']['private']['#value'] = TRUE; + } + + return $form; + } } From e12d53498bafab052b66fff04ee69e0bf243b41c Mon Sep 17 00:00:00 2001 From: Stanislav Kutasevits Date: Wed, 31 Jan 2024 15:50:13 +0200 Subject: [PATCH 07/15] S2FRMS-40 hiding other guardian value for email --- .../WebformElement/MitidChildOtherGuardian.php | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildOtherGuardian.php b/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildOtherGuardian.php index f519de48..53bed78a 100644 --- a/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildOtherGuardian.php +++ b/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildOtherGuardian.php @@ -4,6 +4,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\webform\Plugin\WebformElement\Hidden; +use Drupal\webform\WebformSubmissionInterface; /** * Provides a 'os2forms_mitid_child_other_guardian' element. @@ -17,20 +18,11 @@ */ class MitidChildOtherGuardian extends Hidden { - /** - * {@inheritdoc} - */ - public function form(array $form, FormStateInterface $form_state) { - $form = parent::form($form, $form_state); - - // @see \Drupal\webform\Plugin\WebformElement\WebformEntityReferenceTrait::form - $element_properties = $form_state->get('element_properties'); - - // If element is new, set private by default. - if (empty($element_properties['title'])) { - $form['admin']['private']['#value'] = TRUE; + public function getValue(array $element, WebformSubmissionInterface $webform_submission, array $options = []) { + if (isset($options['email'])) { + return ''; } - return $form; + return parent::getValue($element, $webform_submission, $options); } } From 61e4481438addfead15bd2b03c195bc47c627e26 Mon Sep 17 00:00:00 2001 From: Stanislav Kutasevits Date: Wed, 31 Jan 2024 16:33:48 +0200 Subject: [PATCH 08/15] S2FRMS-40 hiding other guardian value for pdf --- .../src/Plugin/WebformElement/MitidChildOtherGuardian.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildOtherGuardian.php b/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildOtherGuardian.php index 53bed78a..3347c17e 100644 --- a/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildOtherGuardian.php +++ b/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildOtherGuardian.php @@ -2,7 +2,6 @@ namespace Drupal\os2forms_nemid\Plugin\WebformElement; -use Drupal\Core\Form\FormStateInterface; use Drupal\webform\Plugin\WebformElement\Hidden; use Drupal\webform\WebformSubmissionInterface; @@ -19,7 +18,7 @@ class MitidChildOtherGuardian extends Hidden { public function getValue(array $element, WebformSubmissionInterface $webform_submission, array $options = []) { - if (isset($options['email'])) { + if (isset($options['email']) || isset($options['pdf'])) { return ''; } From 1c4210a548b3c4d210d2712f869248b302ad1775 Mon Sep 17 00:00:00 2001 From: Stanislav Kutasevits Date: Tue, 11 Jun 2024 16:51:55 +0300 Subject: [PATCH 09/15] OS-52 Maestro notification cpr_guardian --- .../src/Plugin/WebformHandler/MaestroNotificationHandler.php | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/os2forms_forloeb/src/Plugin/WebformHandler/MaestroNotificationHandler.php b/modules/os2forms_forloeb/src/Plugin/WebformHandler/MaestroNotificationHandler.php index 02c7f943..69d7d9a7 100644 --- a/modules/os2forms_forloeb/src/Plugin/WebformHandler/MaestroNotificationHandler.php +++ b/modules/os2forms_forloeb/src/Plugin/WebformHandler/MaestroNotificationHandler.php @@ -239,6 +239,7 @@ private function getRecipientElementOptions(): array { 'cvr_element', 'cvr_value_element', 'os2forms_person_lookup', + 'os2forms_mitid_child_other_guardian', ]; $isAllowedElement = static fn ($e) => in_array($e['#type'], $elementTypes, TRUE); From 196f8e1890c5a4a83e52d492a21034d41208f28c Mon Sep 17 00:00:00 2001 From: Stanislav Kutasevits Date: Wed, 19 Jun 2024 15:17:30 +0300 Subject: [PATCH 10/15] Cleaning CHANGELOG --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index df601d0a..b822e25b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,7 +46,6 @@ before starting to add changes. Use example [placed in the end of the page](#exa Fix array access with `purge_days` configuration. ## [3.14.1] 2024-01-16 ->>>>>>> develop - CprFetchData adding ajax error fix From 43f795aabb396aa9d5bde98009ede5669aa03143 Mon Sep 17 00:00:00 2001 From: Stanislav Kutasevits Date: Wed, 19 Jun 2024 16:56:54 +0300 Subject: [PATCH 11/15] S2FRMS-40 - PHPCS fixes --- .../src/Element/MitidChildAddress.php | 2 +- .../src/Element/MitidChildApartmentNr.php | 2 +- .../src/Element/MitidChildCoaddress.php | 2 +- .../src/Element/MitidChildHouseNr.php | 2 +- .../src/Element/MitidChildKommunekode.php | 2 +- .../src/Element/MitidChildOtherGuardian.php | 17 ++++++----- .../src/Element/MitidChildPostalCode.php | 2 +- .../MitidChildrenSelectAjaxBehaviour.php | 29 ++++++++++++++++++- .../src/Element/NemidChildrenRadios.php | 18 ++++++------ .../src/Element/NemidChildrenSelect.php | 16 +++++----- .../WebformElement/MitidChildAddress.php | 2 -- .../WebformElement/MitidChildApartmentNr.php | 2 -- .../Plugin/WebformElement/MitidChildCity.php | 2 -- .../WebformElement/MitidChildCoaddress.php | 2 -- .../Plugin/WebformElement/MitidChildCpr.php | 2 -- .../WebformElement/MitidChildElementBase.php | 14 ++++----- .../Plugin/WebformElement/MitidChildFloor.php | 2 -- .../WebformElement/MitidChildHouseNr.php | 2 -- .../WebformElement/MitidChildKommunekode.php | 2 -- .../Plugin/WebformElement/MitidChildName.php | 2 -- .../MitidChildOtherGuardian.php | 4 +++ .../WebformElement/MitidChildPostalCode.php | 2 -- .../WebformElement/MitidChildStreet.php | 2 -- .../ServiceplatformenCprElementBase.php | 4 +-- .../src/Service/FormsHelper.php | 2 +- 25 files changed, 75 insertions(+), 63 deletions(-) diff --git a/modules/os2forms_nemid/src/Element/MitidChildAddress.php b/modules/os2forms_nemid/src/Element/MitidChildAddress.php index f8daa7a6..04850006 100644 --- a/modules/os2forms_nemid/src/Element/MitidChildAddress.php +++ b/modules/os2forms_nemid/src/Element/MitidChildAddress.php @@ -46,7 +46,7 @@ public static function processMitidChildAddress(&$element, FormStateInterface $f } /** - * Webform element validation handler for #type 'os2forms_mitid_child_address'. + * Webform element validation handler for 'os2forms_mitid_child_address'. */ public static function validateMitidChildAddress(&$element, FormStateInterface $form_state, &$complete_form) { // Here you can add custom validation logic. diff --git a/modules/os2forms_nemid/src/Element/MitidChildApartmentNr.php b/modules/os2forms_nemid/src/Element/MitidChildApartmentNr.php index 65cecc7b..82690966 100644 --- a/modules/os2forms_nemid/src/Element/MitidChildApartmentNr.php +++ b/modules/os2forms_nemid/src/Element/MitidChildApartmentNr.php @@ -46,7 +46,7 @@ public static function processMitidChildApartmentNr(&$element, FormStateInterfac } /** - * Webform element validation handler for #type 'os2forms_mitid_child_apartmentNr'. + * Webform element validation handler 'os2forms_mitid_child_apartmentNr'. */ public static function validateMitidChildApartmentNr(&$element, FormStateInterface $form_state, &$complete_form) { // Here you can add custom validation logic. diff --git a/modules/os2forms_nemid/src/Element/MitidChildCoaddress.php b/modules/os2forms_nemid/src/Element/MitidChildCoaddress.php index 87fd6be0..eb208774 100644 --- a/modules/os2forms_nemid/src/Element/MitidChildCoaddress.php +++ b/modules/os2forms_nemid/src/Element/MitidChildCoaddress.php @@ -46,7 +46,7 @@ public static function processMitidChildCoaddress(&$element, FormStateInterface } /** - * Webform element validation handler for #type 'os2forms_mitid_child_coaddress'. + * Webform element validation handler for 'os2forms_mitid_child_coaddress'. */ public static function validateMitidChildCoaddress(&$element, FormStateInterface $form_state, &$complete_form) { // Here you can add custom validation logic. diff --git a/modules/os2forms_nemid/src/Element/MitidChildHouseNr.php b/modules/os2forms_nemid/src/Element/MitidChildHouseNr.php index f07e3d6a..68ff9e57 100644 --- a/modules/os2forms_nemid/src/Element/MitidChildHouseNr.php +++ b/modules/os2forms_nemid/src/Element/MitidChildHouseNr.php @@ -46,7 +46,7 @@ public static function processMitidChildHouseNr(&$element, FormStateInterface $f } /** - * Webform element validation handler for #type 'os2forms_mitid_child_house_nr'. + * Webform element validation handler for 'os2forms_mitid_child_house_nr'. */ public static function validateMitidChildHouseNr(&$element, FormStateInterface $form_state, &$complete_form) { // Here you can add custom validation logic. diff --git a/modules/os2forms_nemid/src/Element/MitidChildKommunekode.php b/modules/os2forms_nemid/src/Element/MitidChildKommunekode.php index 9b773624..1fc3312f 100644 --- a/modules/os2forms_nemid/src/Element/MitidChildKommunekode.php +++ b/modules/os2forms_nemid/src/Element/MitidChildKommunekode.php @@ -46,7 +46,7 @@ public static function processMitidChildKommunekode(&$element, FormStateInterfac } /** - * Webform element validation handler for #type 'os2forms_mitid_child_kommunekode'. + * Webform element validation handler for 'os2forms_mitid_child_kommunekode'. */ public static function validateMitidChildKommunekode(&$element, FormStateInterface $form_state, &$complete_form) { // Here you can add custom validation logic. diff --git a/modules/os2forms_nemid/src/Element/MitidChildOtherGuardian.php b/modules/os2forms_nemid/src/Element/MitidChildOtherGuardian.php index 31e99f9c..b8b54d99 100644 --- a/modules/os2forms_nemid/src/Element/MitidChildOtherGuardian.php +++ b/modules/os2forms_nemid/src/Element/MitidChildOtherGuardian.php @@ -24,21 +24,21 @@ public function getInfo() { $class = static::class; $parentInfo = parent::getInfo() + [ - '#element_validate' => [ - [$class, 'validateMitidChildOtherGuardian'], - ], - ]; + '#element_validate' => [ + [$class, 'validateMitidChildOtherGuardian'], + ], + ]; // Adding custom #pre_render. $parentInfo['#pre_render'] = [ - [$class, 'preRenderMitidChildOtherGuardian'] + [$class, 'preRenderMitidChildOtherGuardian'], ]; return $parentInfo; } /** - * Webform element validation handler for #type 'os2forms_mitid_child_other_guardian'. + * Webform element validation handler 'os2forms_mitid_child_other_guardian'. */ public static function validateMitidChildOtherGuardian(&$element, FormStateInterface $form_state, &$complete_form) { // Here you can add custom validation logic. @@ -49,7 +49,10 @@ public static function validateMitidChildOtherGuardian(&$element, FormStateInter */ public static function preRenderMitidChildOtherGuardian($element) { $element = parent::preRenderHidden($element); - static::setAttributes($element, ['os2forms-mitid-child-other-guardian', 'js-form-type-os2forms-mitid-child-other-guardian']); + static::setAttributes($element, [ + 'os2forms-mitid-child-other-guardian', + 'js-form-type-os2forms-mitid-child-other-guardian', + ]); return $element; } diff --git a/modules/os2forms_nemid/src/Element/MitidChildPostalCode.php b/modules/os2forms_nemid/src/Element/MitidChildPostalCode.php index d78da623..9c6db66c 100644 --- a/modules/os2forms_nemid/src/Element/MitidChildPostalCode.php +++ b/modules/os2forms_nemid/src/Element/MitidChildPostalCode.php @@ -46,7 +46,7 @@ public static function processMitidChildPostalCode(&$element, FormStateInterface } /** - * Webform element validation handler for #type 'os2forms_mitid_child_postal_code'. + * Webform element validation handler for 'os2forms_mitid_child_postal_code'. */ public static function validateMitidChildPostalCode(&$element, FormStateInterface $form_state, &$complete_form) { // Here you can add custom validation logic. diff --git a/modules/os2forms_nemid/src/Element/MitidChildrenSelectAjaxBehaviour.php b/modules/os2forms_nemid/src/Element/MitidChildrenSelectAjaxBehaviour.php index 31570084..2badc955 100644 --- a/modules/os2forms_nemid/src/Element/MitidChildrenSelectAjaxBehaviour.php +++ b/modules/os2forms_nemid/src/Element/MitidChildrenSelectAjaxBehaviour.php @@ -9,10 +9,25 @@ use Drupal\os2forms_nemid\Service\FormsHelper; /** - * Provides a children select ajax behaviour for MitidChildrenSelect and MitidChildrenRadios. + * Provides a children select ajax behaviour. + * + * User in MitidChildrenSelect and MitidChildrenRadios. */ class MitidChildrenSelectAjaxBehaviour { + /** + * Ajax function to update fields after child select. + * + * @param array $form + * Form. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * Form state. + * + * @return \Drupal\Core\Ajax\AjaxResponse + * Ajax response + * + * @throws \Drupal\Component\Plugin\Exception\PluginException + */ public static function mitidChildrenSelectAjax(array &$form, FormStateInterface $form_state) { $response = new AjaxResponse(); @@ -47,46 +62,57 @@ public static function mitidChildrenSelectAjax(array &$form, FormStateInterface $element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getName() : 'Navne- og adressebeskyttet'; $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-name', $element)); break; + case 'os2forms_mitid_child_cpr': $element['#value'] = $cprLookupResult->getCpr(); $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-cpr', $element)); break; + case 'os2forms_mitid_child_address': $element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getAddress() : 'Navne- og adressebeskyttet'; $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-address', $element)); break; + case 'os2forms_mitid_child_apartment_nr': $element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getApartmentNr() : 'Navne- og adressebeskyttet'; $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-apartment-nr', $element)); break; + case 'os2forms_mitid_child_city': $element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getCity() : 'Navne- og adressebeskyttet'; $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-city', $element)); break; + case 'os2forms_mitid_child_coaddress': $element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getCoName() : 'Navne- og adressebeskyttet'; $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-coaddress', $element)); break; + case 'os2forms_mitid_child_floor': $element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getFloor() : 'Navne- og adressebeskyttet'; $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-floor', $element)); break; + case 'os2forms_mitid_child_house_nr': $element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getHouseNr() : 'Navne- og adressebeskyttet'; $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-house-nr', $element)); break; + case 'os2forms_mitid_child_kommunekode': $element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getMunicipalityCode() : 'Navne- og adressebeskyttet'; $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-kommunekode', $element)); break; + case 'os2forms_mitid_child_postal_code': $element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getPostalCode() : 'Navne- og adressebeskyttet'; $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-postal-code', $element)); break; + case 'os2forms_mitid_child_street': $element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getStreet() : 'Navne- og adressebeskyttet'; $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-street', $element)); break; + case 'os2forms_mitid_child_other_guardian': $otherGuardianCpr = NULL; $allGuardians = $cprLookupResult->getGuardians(); @@ -115,4 +141,5 @@ public static function mitidChildrenSelectAjax(array &$form, FormStateInterface return $response; } + } diff --git a/modules/os2forms_nemid/src/Element/NemidChildrenRadios.php b/modules/os2forms_nemid/src/Element/NemidChildrenRadios.php index bf188756..7545f5bb 100644 --- a/modules/os2forms_nemid/src/Element/NemidChildrenRadios.php +++ b/modules/os2forms_nemid/src/Element/NemidChildrenRadios.php @@ -2,7 +2,6 @@ namespace Drupal\os2forms_nemid\Element; -use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Element\Radios; /** @@ -23,14 +22,15 @@ class NemidChildrenRadios extends Radios { */ public function getInfo() { return parent::getInfo() + [ - '#ajax' => [ - 'callback' => [MitidChildrenSelectAjaxBehaviour::class, 'mitidChildrenSelectAjax'], - 'event' => 'change', - 'progress' => [ - 'type' => 'throbber', - 'message' => $this->t('Please wait...'), - ], + '#ajax' => [ + 'callback' => [MitidChildrenSelectAjaxBehaviour::class, 'mitidChildrenSelectAjax'], + 'event' => 'change', + 'progress' => [ + 'type' => 'throbber', + 'message' => $this->t('Please wait...'), ], - ]; + ], + ]; } + } diff --git a/modules/os2forms_nemid/src/Element/NemidChildrenSelect.php b/modules/os2forms_nemid/src/Element/NemidChildrenSelect.php index 567021f4..bc0382d2 100644 --- a/modules/os2forms_nemid/src/Element/NemidChildrenSelect.php +++ b/modules/os2forms_nemid/src/Element/NemidChildrenSelect.php @@ -22,15 +22,15 @@ class NemidChildrenSelect extends Select { */ public function getInfo() { return parent::getInfo() + [ - '#ajax' => [ - 'callback' => [MitidChildrenSelectAjaxBehaviour::class, 'mitidChildrenSelectAjax'], - 'event' => 'change', - 'progress' => [ - 'type' => 'throbber', - 'message' => $this->t('Please wait...'), - ], + '#ajax' => [ + 'callback' => [MitidChildrenSelectAjaxBehaviour::class, 'mitidChildrenSelectAjax'], + 'event' => 'change', + 'progress' => [ + 'type' => 'throbber', + 'message' => $this->t('Please wait...'), ], - ]; + ], + ]; } } diff --git a/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildAddress.php b/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildAddress.php index ace06e71..d1e512ba 100644 --- a/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildAddress.php +++ b/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildAddress.php @@ -2,8 +2,6 @@ namespace Drupal\os2forms_nemid\Plugin\WebformElement; -use Drupal\webform\Plugin\WebformElementBase; - /** * Provides a 'os2forms_mitid_child_address' element. * diff --git a/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildApartmentNr.php b/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildApartmentNr.php index 2abcc654..e8b1ac97 100644 --- a/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildApartmentNr.php +++ b/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildApartmentNr.php @@ -2,8 +2,6 @@ namespace Drupal\os2forms_nemid\Plugin\WebformElement; -use Drupal\webform\Plugin\WebformElementBase; - /** * Provides a 'os2forms_mitid_child_apartment_nr' element. * diff --git a/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildCity.php b/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildCity.php index e99fd58c..002a0962 100644 --- a/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildCity.php +++ b/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildCity.php @@ -2,8 +2,6 @@ namespace Drupal\os2forms_nemid\Plugin\WebformElement; -use Drupal\webform\Plugin\WebformElementBase; - /** * Provides a 'os2forms_mitid_child_city' element. * diff --git a/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildCoaddress.php b/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildCoaddress.php index 35ea0b75..ccb1f535 100644 --- a/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildCoaddress.php +++ b/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildCoaddress.php @@ -2,8 +2,6 @@ namespace Drupal\os2forms_nemid\Plugin\WebformElement; -use Drupal\webform\Plugin\WebformElementBase; - /** * Provides a 'os2forms_mitid_child_coadress' element. * diff --git a/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildCpr.php b/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildCpr.php index 9d26dc05..b16e511f 100644 --- a/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildCpr.php +++ b/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildCpr.php @@ -2,8 +2,6 @@ namespace Drupal\os2forms_nemid\Plugin\WebformElement; -use Drupal\webform\Plugin\WebformElementBase; - /** * Provides a 'os2forms_mitid_child_cpr' element. * diff --git a/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildElementBase.php b/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildElementBase.php index bfe9a630..fbdd7dca 100644 --- a/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildElementBase.php +++ b/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildElementBase.php @@ -24,13 +24,13 @@ public function getDefaultProperties() { // @see \Drupal\webform\Plugin\WebformElementBase::getDefaultProperties // @see \Drupal\webform\Plugin\WebformElementBase::getDefaultBaseProperties $properties = parent::getDefaultProperties() + [ - 'multiple' => '', - 'size' => '', - 'minlength' => '', - 'maxlength' => '', - 'placeholder' => '', - 'readonly' => '', - ]; + 'multiple' => '', + 'size' => '', + 'minlength' => '', + 'maxlength' => '', + 'placeholder' => '', + 'readonly' => '', + ]; return $properties; } diff --git a/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildFloor.php b/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildFloor.php index ec8371b6..c9ac4725 100644 --- a/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildFloor.php +++ b/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildFloor.php @@ -2,8 +2,6 @@ namespace Drupal\os2forms_nemid\Plugin\WebformElement; -use Drupal\webform\Plugin\WebformElementBase; - /** * Provides a 'os2forms_mitid_child_floor' element. * diff --git a/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildHouseNr.php b/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildHouseNr.php index 5f94d38c..62eb97c3 100644 --- a/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildHouseNr.php +++ b/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildHouseNr.php @@ -2,8 +2,6 @@ namespace Drupal\os2forms_nemid\Plugin\WebformElement; -use Drupal\webform\Plugin\WebformElementBase; - /** * Provides a 'os2forms_mitid_child_house_nr' element. * diff --git a/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildKommunekode.php b/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildKommunekode.php index 1413727a..60940db4 100644 --- a/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildKommunekode.php +++ b/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildKommunekode.php @@ -2,8 +2,6 @@ namespace Drupal\os2forms_nemid\Plugin\WebformElement; -use Drupal\webform\Plugin\WebformElementBase; - /** * Provides a 'os2forms_mitid_child_kommunekode' element. * diff --git a/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildName.php b/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildName.php index e5d436f6..d9971f9b 100644 --- a/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildName.php +++ b/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildName.php @@ -2,8 +2,6 @@ namespace Drupal\os2forms_nemid\Plugin\WebformElement; -use Drupal\webform\Plugin\WebformElementBase; - /** * Provides a 'os2forms_mitid_child_name' element. * diff --git a/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildOtherGuardian.php b/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildOtherGuardian.php index 3347c17e..54dc97d5 100644 --- a/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildOtherGuardian.php +++ b/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildOtherGuardian.php @@ -17,6 +17,9 @@ */ class MitidChildOtherGuardian extends Hidden { + /** + * {@inheritdoc} + */ public function getValue(array $element, WebformSubmissionInterface $webform_submission, array $options = []) { if (isset($options['email']) || isset($options['pdf'])) { return ''; @@ -24,4 +27,5 @@ public function getValue(array $element, WebformSubmissionInterface $webform_sub return parent::getValue($element, $webform_submission, $options); } + } diff --git a/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildPostalCode.php b/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildPostalCode.php index 642584cd..1f365c62 100644 --- a/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildPostalCode.php +++ b/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildPostalCode.php @@ -2,8 +2,6 @@ namespace Drupal\os2forms_nemid\Plugin\WebformElement; -use Drupal\webform\Plugin\WebformElementBase; - /** * Provides a 'os2forms_mitid_child_postal_code' element. * diff --git a/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildStreet.php b/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildStreet.php index 606bc25f..44ad2964 100644 --- a/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildStreet.php +++ b/modules/os2forms_nemid/src/Plugin/WebformElement/MitidChildStreet.php @@ -2,8 +2,6 @@ namespace Drupal\os2forms_nemid\Plugin\WebformElement; -use Drupal\webform\Plugin\WebformElementBase; - /** * Provides a 'os2forms_mitid_child_street' element. * diff --git a/modules/os2forms_nemid/src/Plugin/WebformElement/ServiceplatformenCprElementBase.php b/modules/os2forms_nemid/src/Plugin/WebformElement/ServiceplatformenCprElementBase.php index 6567c6e3..e77530a3 100644 --- a/modules/os2forms_nemid/src/Plugin/WebformElement/ServiceplatformenCprElementBase.php +++ b/modules/os2forms_nemid/src/Plugin/WebformElement/ServiceplatformenCprElementBase.php @@ -38,9 +38,9 @@ public function handleElementPrepopulate(array &$element, FormStateInterface &$f } /** - * Appends name and address protected text, if person has name/address protection. + * Appends name/address protected text, if person has name/address protection. * - * @param CprLookupResult $cprLookupResult + * @param \Drupal\os2web_datalookup\LookupResult\CprLookupResult $cprLookupResult * Initialized CprLooupResult. * * @return string diff --git a/modules/os2forms_nemid/src/Service/FormsHelper.php b/modules/os2forms_nemid/src/Service/FormsHelper.php index d25606cc..55ace01b 100644 --- a/modules/os2forms_nemid/src/Service/FormsHelper.php +++ b/modules/os2forms_nemid/src/Service/FormsHelper.php @@ -139,7 +139,7 @@ public function retrieveCprLookupResult(FormStateInterface $form_state) { * CPRLookupResult or NULL. */ public static function retrieveCachedCprLookupResult(FormStateInterface $form_state) { - /** @var CprLookupResult $cprLookupResult */ + /** @var \Drupal\os2web_datalookup\LookupResult\CprLookupResult $cprLookupResult */ $cprLookupResult = NULL; // Trying to fetch person data from cache. From cb6512f318ad3d888a7b7287d09aa2dbcc15f549 Mon Sep 17 00:00:00 2001 From: Stanislav Kutasevits Date: Mon, 8 Jul 2024 13:26:04 +0300 Subject: [PATCH 12/15] Codereview fixes --- .../src/Plugin/WebformElement/NemidChildrenRadios.php | 4 ++-- .../src/Plugin/WebformElement/NemidChildrenSelect.php | 4 ++-- .../WebformElement/ServiceplatformenCprElementBase.php | 10 +++++----- modules/os2forms_nemid/src/Service/FormsHelper.php | 10 +--------- 4 files changed, 10 insertions(+), 18 deletions(-) diff --git a/modules/os2forms_nemid/src/Plugin/WebformElement/NemidChildrenRadios.php b/modules/os2forms_nemid/src/Plugin/WebformElement/NemidChildrenRadios.php index 688c6435..b6f38769 100644 --- a/modules/os2forms_nemid/src/Plugin/WebformElement/NemidChildrenRadios.php +++ b/modules/os2forms_nemid/src/Plugin/WebformElement/NemidChildrenRadios.php @@ -142,7 +142,7 @@ public function handleElementPrepopulate(array &$element, FormStateInterface &$f if (is_array($children) && !empty($children)) { foreach ($children as $child) { if ($child['nameAddressProtected']) { - $options[$child['cpr']] = $child['cpr'] . ' (Navne- og adressebeskyttet)'; + $options[$child['cpr']] = $child['cpr'] . ' (' . t('Name and address protection') . ')'; $showAddressNameProtectionMessage = TRUE; } else { @@ -156,7 +156,7 @@ public function handleElementPrepopulate(array &$element, FormStateInterface &$f $element['#options'] = $options; if ($showAddressNameProtectionMessage) { - $element['#suffix'] = $element['#address_protection_help_text']; + $element['#suffix'] = '
' . $element['#address_protection_help_text'] . '
'; } } diff --git a/modules/os2forms_nemid/src/Plugin/WebformElement/NemidChildrenSelect.php b/modules/os2forms_nemid/src/Plugin/WebformElement/NemidChildrenSelect.php index b49cc3f4..9b41ff38 100644 --- a/modules/os2forms_nemid/src/Plugin/WebformElement/NemidChildrenSelect.php +++ b/modules/os2forms_nemid/src/Plugin/WebformElement/NemidChildrenSelect.php @@ -142,7 +142,7 @@ public function handleElementPrepopulate(array &$element, FormStateInterface &$f if (is_array($children) && !empty($children)) { foreach ($children as $child) { if ($child['nameAddressProtected']) { - $options[$child['cpr']] = $child['cpr'] . ' (Navne- og adressebeskyttet)'; + $options[$child['cpr']] = $child['cpr'] . ' (' . t('Name and address protection') . ')'; $showAddressNameProtectionMessage = TRUE; } else { @@ -156,7 +156,7 @@ public function handleElementPrepopulate(array &$element, FormStateInterface &$f $element['#options'] = $options; if ($showAddressNameProtectionMessage) { - $element['#suffix'] = $element['#address_protection_help_text']; + $element['#suffix'] = '
' . $element['#address_protection_help_text'] . '
'; } } diff --git a/modules/os2forms_nemid/src/Plugin/WebformElement/ServiceplatformenCprElementBase.php b/modules/os2forms_nemid/src/Plugin/WebformElement/ServiceplatformenCprElementBase.php index e77530a3..18e50004 100644 --- a/modules/os2forms_nemid/src/Plugin/WebformElement/ServiceplatformenCprElementBase.php +++ b/modules/os2forms_nemid/src/Plugin/WebformElement/ServiceplatformenCprElementBase.php @@ -31,23 +31,23 @@ public function handleElementPrepopulate(array &$element, FormStateInterface &$f // Appending name and address protection. if (!empty($value)) { - $element['#value'] .= $this->appendNameAddressProtectedText($cprLookupResult); + $element['#value'] .= $this->getNameAddressProtectedText($cprLookupResult); } } } } /** - * Appends name/address protected text, if person has name/address protection. + * Returns name/address protected text, if person has name/address protection. * * @param \Drupal\os2web_datalookup\LookupResult\CprLookupResult $cprLookupResult * Initialized CprLooupResult. * * @return string - * String " (Navne- og adressebeskyttet)" or nothing. + * String indicating Name and Address protection or nothing. */ - public function appendNameAddressProtectedText(CprLookupResult $cprLookupResult) { - return $cprLookupResult->isNameAddressProtected() ? ' (Navne- og adressebeskyttet)' : ''; + public function getNameAddressProtectedText(CprLookupResult $cprLookupResult) { + return $cprLookupResult->isNameAddressProtected() ? ' (' . t('Name and address protection') . ')' : ''; } } diff --git a/modules/os2forms_nemid/src/Service/FormsHelper.php b/modules/os2forms_nemid/src/Service/FormsHelper.php index 55ace01b..0fd62550 100644 --- a/modules/os2forms_nemid/src/Service/FormsHelper.php +++ b/modules/os2forms_nemid/src/Service/FormsHelper.php @@ -139,15 +139,7 @@ public function retrieveCprLookupResult(FormStateInterface $form_state) { * CPRLookupResult or NULL. */ public static function retrieveCachedCprLookupResult(FormStateInterface $form_state) { - /** @var \Drupal\os2web_datalookup\LookupResult\CprLookupResult $cprLookupResult */ - $cprLookupResult = NULL; - - // Trying to fetch person data from cache. - if ($form_state->has('cprLookupResult')) { - $cprLookupResult = $form_state->get('cprLookupResult'); - } - - return $cprLookupResult; + return $form_state->has('cprLookupResult') ? $form_state->get('cprLookupResult') : NULL; } /** From 58fe8c1097e915799d690aa3c528c3f38d035ebd Mon Sep 17 00:00:00 2001 From: Stanislav Kutasevits Date: Mon, 8 Jul 2024 13:40:42 +0300 Subject: [PATCH 13/15] Adding translation options --- .../MitidChildrenSelectAjaxBehaviour.php | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/modules/os2forms_nemid/src/Element/MitidChildrenSelectAjaxBehaviour.php b/modules/os2forms_nemid/src/Element/MitidChildrenSelectAjaxBehaviour.php index 2badc955..d57e973d 100644 --- a/modules/os2forms_nemid/src/Element/MitidChildrenSelectAjaxBehaviour.php +++ b/modules/os2forms_nemid/src/Element/MitidChildrenSelectAjaxBehaviour.php @@ -59,7 +59,7 @@ public static function mitidChildrenSelectAjax(array &$form, FormStateInterface switch ($element['#type']) { case 'os2forms_mitid_child_name': - $element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getName() : 'Navne- og adressebeskyttet'; + $element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getName() : t('Name and address protected'); $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-name', $element)); break; @@ -69,47 +69,47 @@ public static function mitidChildrenSelectAjax(array &$form, FormStateInterface break; case 'os2forms_mitid_child_address': - $element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getAddress() : 'Navne- og adressebeskyttet'; + $element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getAddress() : t('Name and address protected'); $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-address', $element)); break; case 'os2forms_mitid_child_apartment_nr': - $element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getApartmentNr() : 'Navne- og adressebeskyttet'; + $element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getApartmentNr() : t('Name and address protected'); $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-apartment-nr', $element)); break; case 'os2forms_mitid_child_city': - $element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getCity() : 'Navne- og adressebeskyttet'; + $element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getCity() : t('Name and address protected'); $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-city', $element)); break; case 'os2forms_mitid_child_coaddress': - $element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getCoName() : 'Navne- og adressebeskyttet'; + $element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getCoName() : t('Name and address protected'); $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-coaddress', $element)); break; case 'os2forms_mitid_child_floor': - $element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getFloor() : 'Navne- og adressebeskyttet'; + $element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getFloor() : t('Name and address protected'); $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-floor', $element)); break; case 'os2forms_mitid_child_house_nr': - $element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getHouseNr() : 'Navne- og adressebeskyttet'; + $element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getHouseNr() : t('Name and address protected'); $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-house-nr', $element)); break; case 'os2forms_mitid_child_kommunekode': - $element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getMunicipalityCode() : 'Navne- og adressebeskyttet'; + $element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getMunicipalityCode() : t('Name and address protected'); $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-kommunekode', $element)); break; case 'os2forms_mitid_child_postal_code': - $element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getPostalCode() : 'Navne- og adressebeskyttet'; + $element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getPostalCode() : t('Name and address protected'); $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-postal-code', $element)); break; case 'os2forms_mitid_child_street': - $element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getStreet() : 'Navne- og adressebeskyttet'; + $element['#value'] = !$cprLookupResult->isNameAddressProtected() ? $cprLookupResult->getStreet() : t('Name and address protected'); $response->addCommand(new ReplaceCommand('.js-form-type-os2forms-mitid-child-street', $element)); break; From 345a9fdecfce3a26978a0f1ef89416fc6ce1331d Mon Sep 17 00:00:00 2001 From: Stanislav Kutasevits Date: Thu, 11 Jul 2024 13:45:22 +0300 Subject: [PATCH 14/15] S2FRMS-40 Using $this->t() instead of t() --- .../src/Plugin/WebformElement/NemidChildrenRadios.php | 2 +- .../src/Plugin/WebformElement/NemidChildrenSelect.php | 2 +- .../Plugin/WebformElement/ServiceplatformenCprElementBase.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/os2forms_nemid/src/Plugin/WebformElement/NemidChildrenRadios.php b/modules/os2forms_nemid/src/Plugin/WebformElement/NemidChildrenRadios.php index b6f38769..fb88f35f 100644 --- a/modules/os2forms_nemid/src/Plugin/WebformElement/NemidChildrenRadios.php +++ b/modules/os2forms_nemid/src/Plugin/WebformElement/NemidChildrenRadios.php @@ -142,7 +142,7 @@ public function handleElementPrepopulate(array &$element, FormStateInterface &$f if (is_array($children) && !empty($children)) { foreach ($children as $child) { if ($child['nameAddressProtected']) { - $options[$child['cpr']] = $child['cpr'] . ' (' . t('Name and address protection') . ')'; + $options[$child['cpr']] = $child['cpr'] . ' (' . $this->t('Name and address protection') . ')'; $showAddressNameProtectionMessage = TRUE; } else { diff --git a/modules/os2forms_nemid/src/Plugin/WebformElement/NemidChildrenSelect.php b/modules/os2forms_nemid/src/Plugin/WebformElement/NemidChildrenSelect.php index 9b41ff38..eb12d834 100644 --- a/modules/os2forms_nemid/src/Plugin/WebformElement/NemidChildrenSelect.php +++ b/modules/os2forms_nemid/src/Plugin/WebformElement/NemidChildrenSelect.php @@ -142,7 +142,7 @@ public function handleElementPrepopulate(array &$element, FormStateInterface &$f if (is_array($children) && !empty($children)) { foreach ($children as $child) { if ($child['nameAddressProtected']) { - $options[$child['cpr']] = $child['cpr'] . ' (' . t('Name and address protection') . ')'; + $options[$child['cpr']] = $child['cpr'] . ' (' . $this->t('Name and address protection') . ')'; $showAddressNameProtectionMessage = TRUE; } else { diff --git a/modules/os2forms_nemid/src/Plugin/WebformElement/ServiceplatformenCprElementBase.php b/modules/os2forms_nemid/src/Plugin/WebformElement/ServiceplatformenCprElementBase.php index 18e50004..3b23d518 100644 --- a/modules/os2forms_nemid/src/Plugin/WebformElement/ServiceplatformenCprElementBase.php +++ b/modules/os2forms_nemid/src/Plugin/WebformElement/ServiceplatformenCprElementBase.php @@ -47,7 +47,7 @@ public function handleElementPrepopulate(array &$element, FormStateInterface &$f * String indicating Name and Address protection or nothing. */ public function getNameAddressProtectedText(CprLookupResult $cprLookupResult) { - return $cprLookupResult->isNameAddressProtected() ? ' (' . t('Name and address protection') . ')' : ''; + return $cprLookupResult->isNameAddressProtected() ? ' (' . $this->t('Name and address protection') . ')' : ''; } } From 0a39f1da264d61da133509eccc22fbdfd7c750e0 Mon Sep 17 00:00:00 2001 From: Stanislav Kutasevits Date: Fri, 12 Jul 2024 11:47:18 +0300 Subject: [PATCH 15/15] Release 3.15.5 --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c78e07c..52b59afb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,10 @@ before starting to add changes. Use example [placed in the end of the page](#exa ## [Unreleased] -- [S2FRMS-40] Adding child select autopopulate fields +## [3.15.5] 2024-07-12 + +- [#111](https://github.com/OS2Forms/os2forms/pull/111) + Adding child select autopopulate fields ## [3.15.4] 2024-07-08