@@ -29,17 +29,6 @@ public static function getFileContent(array $element, WebformSubmissionInterface
2929 $ nemid_cpr = self ::getFirstValueByType ('os2forms_nemid_cpr ' , $ webform_submission );
3030 $ nemid_com_cvr = self ::getFirstValueByType ('os2forms_nemid_company_cvr ' , $ webform_submission );
3131 $ os2web_datalookup_plugins = \Drupal::service ('plugin.manager.os2web_datalookup ' );
32- /** @var \Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DataLookupInterface $sp_cvr */
33- $ sp_cvr = $ os2web_datalookup_plugins ->createInstance ('serviceplatformen_cvr ' );
34- if (!empty ($ nemid_com_cvr ) && $ sp_cvr ->isReady ()) {
35- $ company_info = $ sp_cvr ->getInfo ($ nemid_com_cvr );
36- if ($ company_info ['status ' ]) {
37- $ nemid_name = htmlspecialchars ($ company_info ['company_name ' ]);
38- $ nemid_address = htmlspecialchars ($ company_info ['company_street ' ] . ' ' . $ company_info ['company_house_nr ' ] . ' ' . $ company_info ['company_ ' ]);
39- $ nemid_city = htmlspecialchars ($ company_info ['company_city ' ]);
40- $ nemid_zipcode = htmlspecialchars ($ company_info ['company_zipcode ' ]);
41- }
42- }
4332 /** @var \Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DataLookupInterface $sp_cpr */
4433 $ sp_cpr = $ os2web_datalookup_plugins ->createInstance ('serviceplatformen_cpr ' );
4534 if (!empty ($ nemid_cpr ) && $ sp_cpr ->isReady ()) {
@@ -51,6 +40,17 @@ public static function getFileContent(array $element, WebformSubmissionInterface
5140 $ nemid_zipcode = htmlspecialchars ($ person_address ['zipcode ' ]);
5241 }
5342 }
43+ /** @var \Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DataLookupInterface $sp_cvr */
44+ $ sp_cvr = $ os2web_datalookup_plugins ->createInstance ('serviceplatformen_cvr ' );
45+ if (!empty ($ nemid_com_cvr ) && $ sp_cvr ->isReady ()) {
46+ $ company_info = $ sp_cvr ->getInfo ($ nemid_com_cvr );
47+ if ($ company_info ['status ' ]) {
48+ $ nemid_name = htmlspecialchars ($ company_info ['company_name ' ]);
49+ $ nemid_address = htmlspecialchars ($ company_info ['company_street ' ] . ' ' . $ company_info ['company_house_nr ' ] . ' ' . $ company_info ['company_ ' ]);
50+ $ nemid_city = htmlspecialchars ($ company_info ['company_city ' ]);
51+ $ nemid_zipcode = htmlspecialchars ($ company_info ['company_zipcode ' ]);
52+ }
53+ }
5454
5555 $ config = self ::getElementConfiguration ($ element );
5656 $ os2formsId = self ::getConfigurationValue ('os2formsId ' , $ config , $ webform_submission );
@@ -83,6 +83,7 @@ public static function getFileContent(array $element, WebformSubmissionInterface
8383 $ webform = $ webform_submission ->getWebform ();
8484 $ webform_title = htmlspecialchars ($ webform ->label ());
8585 $ fields = self ::getWebformElementsAsList ($ webform_submission );
86+
8687 if (isset ($ fields ['antal_rum_max ' ])) {
8788 $ maxRoom = htmlspecialchars ($ fields ['antal_rum_max ' ]);
8889 }
@@ -101,14 +102,14 @@ public static function getFileContent(array $element, WebformSubmissionInterface
101102 $ xml_data = [
102103 'OS2FormsId ' => $ os2formsId ,
103104 'SBSYSJournalisering ' => [
104- 'PrimaerPartCprNummer ' => (!empty ($ nemid_cpr )) ? $ nemid_cpr : '' ,
105+ 'PrimaerPartCprNummer ' => (!empty ($ nemid_cpr ) && empty ( $ nemid_com_cvr ) ) ? $ nemid_cpr : '' ,
105106 'PrimaerPartCvrNummer ' => (!empty ($ nemid_com_cvr )) ? $ nemid_com_cvr : '' ,
106107 'KLe ' => $ kle ,
107108 'SagSkabelonId ' => $ sagSkabelonId ,
108109 ],
109110 'DigitalForsendelse ' => [
110111 'Slutbruger ' => [
111- 'CprNummer ' => (isset ($ nemid_cpr )) ? $ nemid_cpr : '' ,
112+ 'CprNummer ' => (! empty ($ nemid_cpr) && empty ( $ nemid_com_cvr )) ? $ nemid_cpr : '' ,
112113 'CvrNummer ' => (isset ($ nemid_com_cvr )) ? $ nemid_com_cvr : '' ,
113114 'Navn ' => (isset ($ nemid_name )) ? $ nemid_name : '' ,
114115 'Adresse ' => (isset ($ nemid_address )) ? $ nemid_address : '' ,
@@ -199,19 +200,28 @@ protected static function getFirstValueByType($type, WebformSubmissionInterface
199200 * Webform elements as simple array.
200201 */
201202 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 );
202205 $ webform = $ webform_submission ->getWebform ();
203206 $ data = $ webform_submission ->getData ();
204207 $ webform_elements = $ webform ->getElementsInitializedFlattenedAndHasValue ();
205208 $ elements_list = [];
206-
207209 foreach ($ webform_elements as $ key => $ webform_element ) {
208210 $ field_name = $ key ;
209211 $ field_name = preg_replace ('/\W/ ' , '_ ' , $ field_name );
212+ $ webform_element ['#type ' ];
210213 if ($ webform_element ['#type ' ] == 'markup ' ) {
211214 $ elements_list [$ field_name ] = $ webform_element ['value ' ];
212215 }
213216 elseif ($ data && isset ($ data [$ key ])) {
214- $ 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+ }
215225 }
216226 }
217227 return $ elements_list ;
0 commit comments