Skip to content

Commit daaf3da

Browse files
committed
OS2FORMS-359 adding children information
1 parent 3dcbfe7 commit daaf3da

File tree

2 files changed

+60
-10
lines changed

2 files changed

+60
-10
lines changed

src/LookupResult/CprLookupResult.php

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ class CprLookupResult {
114114
*/
115115
protected $nameAddressProtected;
116116

117+
/**
118+
* Array of children.
119+
*
120+
* @var array
121+
*/
122+
protected $children = [];
123+
117124
/**
118125
* @return bool
119126
*/
@@ -311,11 +318,38 @@ public function setNameAddressProtected(bool $nameAddressProtected): void {
311318
}
312319

313320
/**
314-
* Returns the value of the provided field.
321+
* Returns the children.
315322
*
316-
* @param $field
317-
* Field name;
318-
*/
323+
* @return array
324+
* Children array as
325+
* [
326+
* 0 => [
327+
* 'cpr' => xxxxx,
328+
* 'name' => full name,
329+
* ],
330+
* ...
331+
* ]
332+
*/
333+
public function getChildren(): array {
334+
return $this->children;
335+
}
336+
337+
/**
338+
* Sets the children.
339+
*
340+
* @param array $children
341+
* Children array as
342+
* [
343+
* 0 => [
344+
* 'cpr' => xxxxx,
345+
* 'name' => full name,
346+
* ],
347+
* ...
348+
* ]
349+
*/
350+
public function setChildren(array $children): void {
351+
$this->children = $children;
352+
}
319353

320354
/**
321355
* Returns the value of the provided field.

src/Plugin/os2web/DataLookup/ServiceplatformenCPRExtended.php

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,15 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s
7575
/**
7676
* @inheritDoc
7777
*/
78-
public function lookup($cpr) {
78+
public function lookup($cpr, $allowCprTestModeReplace = TRUE) {
7979
if ($this->configuration['mode_selector'] == 1 && $this->configuration['test_mode_fixed_cpr']) {
80-
$cpr = $this->configuration['test_mode_fixed_cpr'];
81-
\Drupal::messenger()->addMessage(
82-
$this->t("Test mode enabled, all CPR lookup requests are made against CPR: %cpr", ['%cpr' => $cpr]),
83-
MessengerInterface::TYPE_STATUS
84-
);
80+
if ($allowCprTestModeReplace) {
81+
$cpr = $this->configuration['test_mode_fixed_cpr'];
82+
\Drupal::messenger()->addMessage(
83+
$this->t("Test mode enabled, all CPR lookup requests are made against CPR: %cpr", ['%cpr' => $cpr]),
84+
MessengerInterface::TYPE_STATUS
85+
);
86+
}
8587
}
8688

8789
$request = $this->prepareRequest();
@@ -112,6 +114,20 @@ public function lookup($cpr) {
112114
$cprResult->setAddress($address->aktuelAdresse->standardadresse ?? '');
113115
}
114116

117+
$relationship = $result['relationer'];
118+
if ($relationship->barn && is_array($relationship->barn)) {
119+
$children = [];
120+
foreach ($relationship->barn as $child) {
121+
$childCprResult = $this->lookup($child->personnummer, FALSE);
122+
123+
$children[] = [
124+
'cpr' => $childCprResult->getCpr(),
125+
'name' => $childCprResult->getName()
126+
];
127+
}
128+
$cprResult->setChildren($children);
129+
}
130+
115131
// Leaving empty, no information in webservice.
116132
$cprResult->setCoName('');
117133
$cprResult->setNameAddressProtected(FALSE);

0 commit comments

Comments
 (0)