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
17 changes: 10 additions & 7 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\DatafordelerMartikulaLookupInterface $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();

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

// 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: 8 additions & 17 deletions modules/os2forms_dawa/src/Element/DawaElementBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,17 @@ 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'];

$parameters = new ParameterBag($element['#autocomplete_route_parameters']);
$parameters->set('q', $value);
/** @var \Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DatafordelerAddressLookupInterface $datafordelerAddressLookup */
$datafordelerAddressLookup = \Drupal::service('plugin.manager.os2web_datalookup')->createInstance('datafordeler_address_lookup');
Comment on lines +39 to +40
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.

We could move this into the if to avoid unnecessary instantiation when it is not a os2forms_dawa_address-element.


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

case 'os2forms_dawa_block':
$matches = $dawaService->getBlockMatches($parameters);
break;
$element_type = $element['#type'];

case 'os2forms_dawa_matrikula':
$matches = $dawaService->getMatrikulaMatches($parameters);
break;
if ($element_type == 'os2forms_dawa_address') {
$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
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?

'#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
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
*
* @WebformElement(
* id = "os2forms_dawa_matrikula",
* label = @Translation("DAWA Matrikula (autocomplete)"),
* description = @Translation("Provides a DAWA Matrikula Autocomplete element."),
* label = @Translation("DAWA Matrikula (autocomplete) - DEPRECATED"),
* description = @Translation("Provides a DAWA Matrikula 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
Loading