@@ -40,7 +40,6 @@ public static function getFileContent(array $element, WebformSubmissionInterface
4040 $ nemid_zipcode = htmlspecialchars ($ person_address ['zipcode ' ]);
4141 }
4242 }
43-
4443 /** @var \Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DataLookupInterface $sp_cvr */
4544 $ sp_cvr = $ os2web_datalookup_plugins ->createInstance ('serviceplatformen_cvr ' );
4645 if (!empty ($ nemid_com_cvr ) && $ sp_cvr ->isReady ()) {
@@ -84,6 +83,7 @@ public static function getFileContent(array $element, WebformSubmissionInterface
8483 $ webform = $ webform_submission ->getWebform ();
8584 $ webform_title = htmlspecialchars ($ webform ->label ());
8685 $ fields = self ::getWebformElementsAsList ($ webform_submission );
86+
8787 if (isset ($ fields ['antal_rum_max ' ])) {
8888 $ maxRoom = htmlspecialchars ($ fields ['antal_rum_max ' ]);
8989 }
@@ -102,14 +102,14 @@ public static function getFileContent(array $element, WebformSubmissionInterface
102102 $ xml_data = [
103103 'OS2FormsId ' => $ os2formsId ,
104104 'SBSYSJournalisering ' => [
105- 'PrimaerPartCprNummer ' => (!empty ($ nemid_cpr )) ? $ nemid_cpr : '' ,
105+ 'PrimaerPartCprNummer ' => (!empty ($ nemid_cpr ) && empty ( $ nemid_com_cvr ) ) ? $ nemid_cpr : '' ,
106106 'PrimaerPartCvrNummer ' => (!empty ($ nemid_com_cvr )) ? $ nemid_com_cvr : '' ,
107107 'KLe ' => $ kle ,
108108 'SagSkabelonId ' => $ sagSkabelonId ,
109109 ],
110110 'DigitalForsendelse ' => [
111111 'Slutbruger ' => [
112- 'CprNummer ' => (isset ($ nemid_cpr )) ? $ nemid_cpr : '' ,
112+ 'CprNummer ' => (! empty ($ nemid_cpr) && empty ( $ nemid_com_cvr )) ? $ nemid_cpr : '' ,
113113 'CvrNummer ' => (isset ($ nemid_com_cvr )) ? $ nemid_com_cvr : '' ,
114114 'Navn ' => (isset ($ nemid_name )) ? $ nemid_name : '' ,
115115 'Adresse ' => (isset ($ nemid_address )) ? $ nemid_address : '' ,
@@ -200,19 +200,28 @@ protected static function getFirstValueByType($type, WebformSubmissionInterface
200200 * Webform elements as simple array.
201201 */
202202 protected static function getWebformElementsAsList (WebformSubmissionInterface $ webform_submission ) {
203+ $ nemid_cpr = self ::getFirstValueByType ('os2forms_nemid_cpr ' , $ webform_submission );
204+ $ nemid_com_cvr = self ::getFirstValueByType ('os2forms_nemid_company_cvr ' , $ webform_submission );
203205 $ webform = $ webform_submission ->getWebform ();
204206 $ data = $ webform_submission ->getData ();
205207 $ webform_elements = $ webform ->getElementsInitializedFlattenedAndHasValue ();
206208 $ elements_list = [];
207-
208209 foreach ($ webform_elements as $ key => $ webform_element ) {
209210 $ field_name = $ key ;
210211 $ field_name = preg_replace ('/\W/ ' , '_ ' , $ field_name );
212+ $ webform_element ['#type ' ];
211213 if ($ webform_element ['#type ' ] == 'markup ' ) {
212214 $ elements_list [$ field_name ] = $ webform_element ['value ' ];
213215 }
214216 elseif ($ data && isset ($ data [$ key ])) {
215- $ elements_list [$ field_name ] = $ data [$ key ];
217+ if ($ webform_element ['#type ' ] == 'os2forms_nemid_cpr ' ) {
218+ if (!empty ($ nemid_cpr ) && empty ($ nemid_com_cvr )) {
219+ $ elements_list [$ field_name ] = $ data [$ key ];
220+ }
221+ }
222+ else {
223+ $ elements_list [$ field_name ] = $ data [$ key ];
224+ }
216225 }
217226 }
218227 return $ elements_list ;
0 commit comments