Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ before starting to add changes. Use example [placed in the end of the page](#exa
- git actions check
- [PR-289](https://github.com/OS2Forms/os2forms/pull/289)
Added required "Zoom control position" to map element
- [#246](https://github.com/OS2Forms/os2forms/issues/246)
Adding Datafordeler address lookup

## [5.0.0] 2025-11-18

Expand Down
4 changes: 0 additions & 4 deletions modules/os2forms_dawa/os2forms_dawa.services.yml

This file was deleted.

32 changes: 11 additions & 21 deletions modules/os2forms_dawa/src/Controller/DawaElementController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Drupal\os2forms_dawa\Controller;

use Drupal\Core\Controller\ControllerBase;
use Drupal\os2forms_dawa\Service\DawaService;
use Drupal\os2web_datalookup\Plugin\DataLookupManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -14,28 +14,28 @@
class DawaElementController extends ControllerBase {

/**
* The DAWA service object.
* Datafordeler address lookup.
*
* @var \Drupal\os2forms_dawa\Service\DawaService
* @var \Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DatafordelerAddressLookupInterface
*/
protected $dawaService;
protected $datafordelerAddressLookup;

/**
* Constructs a DawaElementController object.
*
* @param \Drupal\os2forms_dawa\Service\DawaService $os2forms_dawa_service
* The DAWA service object.
* @param \Drupal\os2web_datalookup\Plugin\DataLookupManager $dataLookupManager
* Datalookup manager.
*/
public function __construct(DawaService $os2forms_dawa_service) {
$this->dawaService = $os2forms_dawa_service;
public function __construct(DataLookupManager $dataLookupManager) {
$this->datafordelerAddressLookup = $dataLookupManager->createInstance('datafordeler_address_lookup');
}

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('os2forms_dawa.service')
$container->get('plugin.manager.os2web_datalookup')
);
}

Expand All @@ -61,18 +61,8 @@ public function autocomplete(Request $request, $element_type) {
$matches = [];

// Get the matches based on the element type.
switch ($element_type) {
case 'os2forms_dawa_address':
$matches = $this->dawaService->getAddressMatches($query);
break;

case 'os2forms_dawa_block':
$matches = $this->dawaService->getBlockMatches($query);
break;

case 'os2forms_dawa_matrikula':
$matches = $this->dawaService->getMatrikulaMatches($query);
break;
if ($element_type == 'os2forms_dawa_address') {
$matches = $this->datafordelerAddressLookup->getAddressMatches($query);
}

return new JsonResponse($matches);
Expand Down
19 changes: 11 additions & 8 deletions modules/os2forms_dawa/src/Element/DawaElementAddressMatrikula.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,29 +96,32 @@ public static function getCompositeElements(array $element) {
private static function getMatrikulaOptions($addressValue, array $element) {
$options = [];

/** @var \Drupal\os2forms_dawa\Service\DawaService $dawaService */
$dawaService = \Drupal::service('os2forms_dawa.service');
/** @var \Drupal\os2web_datalookup\Plugin\DataLookupManager $datalookupManager */
$datalookupManager = \Drupal::service('plugin.manager.os2web_datalookup');

/** @var \Drupal\os2forms_dawa\Plugin\os2web\DataLookup\DatafordelerDataLookupInterface $datafordelerLookup */
$datafordelerLookup = \Drupal::service('plugin.manager.os2web_datalookup')->createInstance('datafordeler_data_lookup');
/** @var \Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DatafordelerAddressLookupInterface $addressLookup */
$addressLookup = $datalookupManager->createInstance('datafordeler_address_lookup');

/** @var \Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DatafordelerMatrikulaLookupInterface $matrikulaLookup */
$matrikulaLookup = $datalookupManager->createInstance('datafordeler_matrikula_lookup');

// Getting address.
$addressParams = new ParameterBag();
$addressParams->set('q', $addressValue);
if (isset($element['#limit_by_municipality'])) {
$addressParams->set('limit_by_municipality', $element['#limit_by_municipality']);
}
$address = $dawaService->getSingleAddress($addressParams);
$address = $addressLookup->getSingleAddress($addressParams);

if ($address) {
$addressAccessId = $address->getAccessAddressId();
$addressHouseId = $address->getHouseId();

// Find matrikula list from the houseid (husnummer):
$matrikulaId = $datafordelerLookup->getMatrikulaId($addressAccessId);
$matrikulaId = $matrikulaLookup->getMatrikulaId($addressHouseId);

// Find Matrikula entries from matrikulas ID.
if ($matrikulaId) {
$matrikulaEnties = $datafordelerLookup->getMatrikulaEntries($matrikulaId);
$matrikulaEnties = $matrikulaLookup->getMatrikulaEntries($matrikulaId);
foreach ($matrikulaEnties as $matrikula) {
$matrikulaOption = $matrikula->getMatrikulaNumber() . ' ' . $matrikula->getOwnershipName();

Expand Down
25 changes: 7 additions & 18 deletions modules/os2forms_dawa/src/Element/DawaElementBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,15 @@ public static function validateDawaElementBase(&$element, FormStateInterface $fo
}

if (!empty($value)) {
/** @var \Drupal\os2forms_dawa\Service\DawaService $dawaService*/
$dawaService = \Drupal::service('os2forms_dawa.service');
$matches = [];

$element_type = $element['#type'];
if ($element['#type'] == 'os2forms_dawa_address') {
/** @var \Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DatafordelerAddressLookupInterface $datafordelerAddressLookup */
$datafordelerAddressLookup = \Drupal::service('plugin.manager.os2web_datalookup')->createInstance('datafordeler_address_lookup');

$parameters = new ParameterBag($element['#autocomplete_route_parameters']);
$parameters->set('q', $value);

switch ($element_type) {
case 'os2forms_dawa_address':
$matches = $dawaService->getAddressMatches($parameters);
break;

case 'os2forms_dawa_block':
$matches = $dawaService->getBlockMatches($parameters);
break;

case 'os2forms_dawa_matrikula':
$matches = $dawaService->getMatrikulaMatches($parameters);
break;
$parameters = new ParameterBag($element['#autocomplete_route_parameters']);
$parameters->set('q', $value);
$matches = $datafordelerAddressLookup->getAddressMatches($parameters);
}

// Checking if the current value is within the list of the values from an
Expand Down
79 changes: 0 additions & 79 deletions modules/os2forms_dawa/src/Entity/DatafordelerMatrikula.php

This file was deleted.

135 changes: 0 additions & 135 deletions modules/os2forms_dawa/src/Entity/DawaAddress.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public function form(array $form, FormStateInterface $form_state) {
];
$form['autocomplete']['limit_by_municipality'] = [
'#type' => 'textfield',
'#title' => $this->t('Limit by municipality (-es)'),
'#pattern' => '^(\d{3},?)*$',
'#description' => $this->t('CSV list of municipalities codes, what will limit the address lookup.'),
'#title' => $this->t('Limit by municipality'),
'#pattern' => '^(\d{4})$',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So only single municipality limits now? Also, would this not silently break existing webforms?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the worst case, that would produce empty result (if there has been a multivalue value before).

We haven't talked about any migration logic, i also don't see any good migration logic here. I would say that is a manual process after migration, @ds-bellcom what is your say on this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any clear migration logic either. If this limitation is indeed intended we need to ensure webform builders are made aware of it! Let's see what @ds-bellcom has to say :-)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stankut @jekuaitk As I understand the new API from Klimadatastyrelsen, multiple municipality codes are not supported - see here: https://confluence.sdfi.dk/pages/viewpage.action?pageId=244318431

Regardless of whether you use "Husnummersøgning" or "Adressesøgning", the "kommunekode" must only be 4 digits - no more, no less.

I don't see any good migration solution - other than that the forms where the DAWA elements are used are reviewed. This is of course something that needs to be communicated to the users so that they can do this review.

'#description' => $this->t('Municipatity code, what will limit the address lookup. Single number, 4 digits, e.g. 0661'),
];

return $form;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
*
* @WebformElement(
* id = "os2forms_dawa_block",
* label = @Translation("DAWA Block (autocomplete)"),
* description = @Translation("Provides a DAWA Block Autocomplete element."),
* label = @Translation("DAWA Block (autocomplete) - DEPRECATED"),
* description = @Translation("Provides a DAWA Block Autocomplete element. This element is deprecated due to the API being phased out. There is no provided alternative for this element."),
* category = @Translation("DAWA"),
* )
*/
Expand Down
Loading