Skip to content

Commit 3e02eee

Browse files
authored
Merge branch 'develop' into release/3.16.0
2 parents bbdbba2 + e1eb43c commit 3e02eee

File tree

51 files changed

+2200
-71
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2200
-71
lines changed

CHANGELOG.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,28 @@ before starting to add changes. Use example [placed in the end of the page](#exa
2525
- Reduntand dependency removing - webform_scheduled_tasks
2626
- Drupal 10 compability fixes
2727

28+
## [3.15.6] 2024-07-16
29+
30+
- [#120](https://github.com/OS2Forms/os2forms/pull/120)
31+
S2FRMS-100 / OS-74 - changing address fetch API
32+
33+
## [3.15.5] 2024-07-12
34+
35+
- [#111](https://github.com/OS2Forms/os2forms/pull/111)
36+
Adding child select autopopulate fields
37+
38+
## [3.15.4] 2024-07-08
39+
40+
- [#117](https://github.com/OS2Forms/os2forms/pull/117)
41+
Encrypts all elements if encryption enabled.
42+
- [#114](https://github.com/OS2Forms/os2forms/pull/114)
43+
Encrypted computed elements.
44+
- [OS-74] Updating DAWA matrikula select with Datafordeler select
45+
46+
## [3.15.3] 2024-06-25
47+
48+
- [OS-74] Replacing DAWA matrikula select with Datafordeler select
49+
2850
## [3.15.2] 2024-05-27
2951

3052
- [#108](https://github.com/OS2Forms/os2forms/pull/108)
@@ -244,7 +266,9 @@ before starting to add changes. Use example [placed in the end of the page](#exa
244266
- Security in case of vulnerabilities.
245267
```
246268

247-
[Unreleased]: https://github.com/OS2Forms/os2forms/compare/3.15.2...HEAD
269+
[Unreleased]: https://github.com/OS2Forms/os2forms/compare/3.15.4...HEAD
270+
[3.15.4]: https://github.com/OS2Forms/os2forms/compare/3.15.3...3.15.4
271+
[3.15.3]: https://github.com/OS2Forms/os2forms/compare/3.15.2...3.15.3
248272
[3.15.2]: https://github.com/OS2Forms/os2forms/compare/3.15.1...3.15.2
249273
[3.15.1]: https://github.com/OS2Forms/os2forms/compare/3.15.0...3.15.1
250274
[3.15.0]: https://github.com/OS2Forms/os2forms/compare/3.14.1...3.15.0

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@
9898
"2733781 - Add Export to Word Support": "https://www.drupal.org/files/issues/2019-11-22/2733781-47.patch"
9999
},
100100
"drupal/webform": {
101-
"Unlock possibility of using Entity print module export to Word": "https://www.drupal.org/files/issues/2020-02-29/3096552-6.patch"
101+
"Unlock possibility of using Entity print module export to Word": "https://www.drupal.org/files/issues/2020-02-29/3096552-6.patch",
102+
"Webform computed element post save alter": "https://www.drupal.org/files/issues/2024-06-25/webform_computed_post_save_field_alter.patch"
102103
},
103104
"drupal/coc_forms_auto_export": {
104105
"3240592 - Problem with phpseclib requirement in 2.x (https://www.drupal.org/project/coc_forms_auto_export/issues/3240592)": "https://www.drupal.org/files/issues/2021-10-04/requirement-namespace-3240592-1.patch",

modules/os2forms_dawa/src/Element/DawaElementAddressMatrikula.php

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,14 @@ public static function getCompositeElements(array $element) {
9494
* Array of matrikula options key and the values are identical.
9595
*/
9696
private static function getMatrikulaOptions($addressValue, array $element) {
97+
$options = [];
98+
9799
/** @var \Drupal\os2forms_dawa\Service\DawaService $dawaService */
98100
$dawaService = \Drupal::service('os2forms_dawa.service');
99101

102+
/** @var \Drupal\os2forms_dawa\Plugin\os2web\DataLookup\DatafordelerDataLookupInterface $datafordelerLookup */
103+
$datafordelerLookup = \Drupal::service('plugin.manager.os2web_datalookup')->createInstance('datafordeler_data_lookup');
104+
100105
// Getting address.
101106
$addressParams = new ParameterBag();
102107
$addressParams->set('q', $addressValue);
@@ -106,29 +111,27 @@ private static function getMatrikulaOptions($addressValue, array $element) {
106111
$address = $dawaService->getSingleAddress($addressParams);
107112

108113
if ($address) {
109-
// Getting matrikula options.
110-
$matrikulaParams = new ParameterBag();
111-
// Getting municipality code from address.
112-
if ($municipality_code = $address->getMunicipalityCode()) {
113-
$matrikulaParams->set('limit_by_municipality', $municipality_code);
114-
}
115-
// Getting property nr from address.
116-
if ($property_nr = $address->getPropertyNumber()) {
117-
$matrikulaParams->set('limit_by_property', $property_nr);
118-
}
119-
// If the matrikula option must not have the code.
120-
if (isset($element['#remove_code'])) {
121-
$matrikulaParams->set('remove_code', $element['#remove_code']);
122-
}
114+
$addressAccessId = $address->getAccessAddressId();
123115

124-
// Get the options.
125-
$matrikulaOptions = $dawaService->getMatrikulaMatches($matrikulaParams);
116+
// Find matrikula list from the houseid (husnummer):
117+
$matrikulaId = $datafordelerLookup->getMatrikulaId($addressAccessId);
126118

127-
// Use values as keys.
128-
return array_combine($matrikulaOptions, $matrikulaOptions);
119+
// Find Matrikula entries from matrikulas ID.
120+
if ($matrikulaId) {
121+
$matrikulaEnties = $datafordelerLookup->getMatrikulaEntries($matrikulaId);
122+
foreach ($matrikulaEnties as $matrikula) {
123+
$matrikulaOption = $matrikula->getMatrikulaNumber() . ' ' . $matrikula->getOwnershipName();
124+
125+
if (isset($element['#remove_code']) && !$element['#remove_code']) {
126+
$matrikulaOption .= ' (' . $matrikula->getOwnerLicenseCode() . ')';
127+
}
128+
129+
$options[$matrikulaOption] = $matrikulaOption;
130+
}
131+
}
129132
}
130133

131-
return [];
134+
return $options;
132135
}
133136

134137
/**
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
namespace Drupal\os2forms_dawa\Entity;
4+
5+
/**
6+
* Class DatafordelerMatrikula.
7+
*
8+
* Wrapper class for Datafordeler matrikula object that easies
9+
* the matrikula property access.
10+
*/
11+
class DatafordelerMatrikula {
12+
13+
/**
14+
* Owner licence code / ejerlavskode.
15+
*
16+
* @var string
17+
*/
18+
protected string $ownerLicenseCode;
19+
20+
/**
21+
* Ownership name / ejerlavsnavn.
22+
*
23+
* @var string
24+
*/
25+
protected string $ownershipName;
26+
27+
28+
/**
29+
* Matrikula number / matrikelnummer.
30+
*
31+
* @var string
32+
*/
33+
protected string $matrikulaNumber;
34+
35+
/**
36+
* DawaAddress constructor.
37+
*
38+
* Fills the property from the provided JSON metadata.
39+
*
40+
* @param array $json
41+
* Address properties as JSON metadata.
42+
*/
43+
public function __construct(array $json) {
44+
$this->ownerLicenseCode = $json['properties']['ejerlavskode'];
45+
$this->ownershipName = $json['properties']['ejerlavsnavn'];
46+
$this->matrikulaNumber = $json['properties']['matrikelnummer'];
47+
}
48+
49+
/**
50+
* Returns owner licence code.
51+
*
52+
* @return string
53+
* Owners licence code.
54+
*/
55+
public function getOwnerLicenseCode(): string {
56+
return $this->ownerLicenseCode;
57+
}
58+
59+
/**
60+
* Returns ownership name.
61+
*
62+
* @return string
63+
* ownership name.
64+
*/
65+
public function getOwnershipName(): string {
66+
return $this->ownershipName;
67+
}
68+
69+
/**
70+
* Returns makrikula number.
71+
*
72+
* @return string
73+
* Matrikula number
74+
*/
75+
public function getMatrikulaNumber(): string {
76+
return $this->matrikulaNumber;
77+
}
78+
79+
}

modules/os2forms_dawa/src/Entity/DawaAddress.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ class DawaAddress {
4545
*/
4646
protected $longitude;
4747

48+
/**
49+
* Address access ID.
50+
*
51+
* @var string
52+
*/
53+
protected $accessAddressId;
54+
4855
/**
4956
* DawaAddress constructor.
5057
*
@@ -61,6 +68,7 @@ public function __construct(array $json) {
6168
$this->propertyNumber = $json['adgangsadresse']['esrejendomsnr'];
6269
$this->longitude = $json['adgangsadresse']['adgangspunkt']['koordinater'][0];
6370
$this->latitude = $json['adgangsadresse']['adgangspunkt']['koordinater'][1];
71+
$this->accessAddressId = $json['adgangsadresse']['id'];
6472
}
6573
}
6674

@@ -114,4 +122,14 @@ public function getLongitude() {
114122
return $this->longitude;
115123
}
116124

125+
/**
126+
* Gets Address access ID.
127+
*
128+
* @return string
129+
* Address access ID.
130+
*/
131+
public function getAccessAddressId() {
132+
return $this->accessAddressId;
133+
}
134+
117135
}
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<?php
2+
3+
namespace Drupal\os2forms_dawa\Plugin\os2web\DataLookup;
4+
5+
use Drupal\Component\Utility\NestedArray;
6+
use Drupal\Core\Form\FormStateInterface;
7+
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
8+
use Drupal\os2forms_dawa\Entity\DatafordelerMatrikula;
9+
use Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DataLookupBase;
10+
use GuzzleHttp\ClientInterface;
11+
use Symfony\Component\DependencyInjection\ContainerInterface;
12+
13+
/**
14+
* Defines a plugin for Datafordeler Data.
15+
*
16+
* @DataLookup(
17+
* id = "datafordeler_data_lookup",
18+
* label = @Translation("Datafordeler Address Lookup"),
19+
* )
20+
*/
21+
class DatafordelerDataLookup extends DataLookupBase implements DatafordelerDataLookupInterface, ContainerFactoryPluginInterface {
22+
23+
/**
24+
* The HTTP client to fetch the feed data with.
25+
*
26+
* @var \GuzzleHttp\ClientInterface
27+
*/
28+
protected $httpClient;
29+
30+
/**
31+
* {@inheritdoc}
32+
*/
33+
public function __construct(array $configuration, $plugin_id, $plugin_definition, ClientInterface $httpClient) {
34+
$this->httpClient = $httpClient;
35+
parent::__construct($configuration, $plugin_id, $plugin_definition);
36+
}
37+
38+
/**
39+
* {@inheritdoc}
40+
*/
41+
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
42+
return new static(
43+
$configuration,
44+
$plugin_id,
45+
$plugin_definition,
46+
$container->get('http_client'),
47+
);
48+
}
49+
50+
/**
51+
* {@inheritdoc}
52+
*/
53+
public function getMatrikulaId(string $addressAccessId) : ?string {
54+
$url = "https://services.datafordeler.dk/DAR/DAR/3.0.0/rest/husnummerTilJordstykke";
55+
56+
$json = $this->httpClient->request('GET', $url, [
57+
'query' => [
58+
'husnummerid' => $addressAccessId,
59+
],
60+
])->getBody();
61+
62+
$jsonDecoded = json_decode($json, TRUE);
63+
if (is_array($jsonDecoded)) {
64+
if (NestedArray::keyExists($jsonDecoded, ['gældendeJordstykke', 'jordstykkeLokalId'])) {
65+
return NestedArray::getValue($jsonDecoded, ['gældendeJordstykke', 'jordstykkeLokalId']);
66+
}
67+
}
68+
69+
return NULL;
70+
}
71+
72+
/**
73+
* {@inheritdoc}
74+
*/
75+
public function getMatrikulaEntries(string $matrikulaId) : array {
76+
$matrikulaEntries = [];
77+
$url = "https://services.datafordeler.dk/Matriklen2/Matrikel/2.0.0/rest/SamletFastEjendom";
78+
79+
$configuration = $this->getConfiguration();
80+
$json = $this->httpClient->request('GET', $url, [
81+
'query' => [
82+
'jordstykkeid' => $matrikulaId,
83+
'username' => $configuration['username'],
84+
'password' => $configuration['password'],
85+
],
86+
])->getBody();
87+
88+
$jsonDecoded = json_decode($json, TRUE);
89+
90+
if (is_array($jsonDecoded)) {
91+
if (NestedArray::keyExists($jsonDecoded, ['features', 0, 'properties', 'jordstykke'])) {
92+
$jordstykker = NestedArray::getValue($jsonDecoded, ['features', 0, 'properties', 'jordstykke']);
93+
foreach ($jordstykker as $jordstyk) {
94+
$matrikulaEntries[] = new DatafordelerMatrikula($jordstyk);
95+
}
96+
}
97+
}
98+
99+
return $matrikulaEntries;
100+
}
101+
102+
/**
103+
* {@inheritdoc}
104+
*/
105+
public function defaultConfiguration() {
106+
return [
107+
'username' => '',
108+
'password' => '',
109+
] + parent::defaultConfiguration();
110+
}
111+
112+
/**
113+
* {@inheritdoc}
114+
*/
115+
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
116+
$form['username'] = [
117+
'#type' => 'textfield',
118+
'#title' => $this->t('Username for service calls'),
119+
'#default_value' => $this->configuration['username'],
120+
'#required' => TRUE,
121+
'#description' => $this->t('Username required for performing API requests'),
122+
];
123+
$form['password'] = [
124+
'#type' => 'textfield',
125+
'#title' => $this->t('Password for service calls'),
126+
'#default_value' => $this->configuration['password'],
127+
'#required' => TRUE,
128+
'#description' => $this->t('Password required for performing API requests'),
129+
];
130+
131+
return $form;
132+
}
133+
134+
/**
135+
* {@inheritdoc}
136+
*/
137+
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
138+
$configuration = $this->getConfiguration();
139+
$configuration['username'] = $form_state->getValue('username');
140+
$configuration['password'] = $form_state->getValue('password');
141+
$this->setConfiguration($configuration);
142+
}
143+
144+
}

0 commit comments

Comments
 (0)