Skip to content
Merged
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 @@ -30,6 +30,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
- [#251](https://github.com/OS2Forms/os2forms/issues/251)
Updated Webform encrypt uninstall problem fix

Expand Down
17 changes: 17 additions & 0 deletions modules/os2forms_dawa/js/dawa_address_autocomplete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
(function ($, Drupal) {
// Overrides splitValues() function found in core/misc/autocomplete.js for
// DAWA elements. Danish addresses contain commas. Original splitValues()
// method splits upon commas. Combined with default extractLastTerm this
// results in unexpected behavior when using autocomplete with respect to
// danish addresses. Inspired by
// https://www.drupal.org/project/drupal/issues/2821181#comment-12012538.
Drupal.autocomplete.splitValues = function (value) {
// Check if the current autocomplete is for a focused DAWA address field
if ($('.ui-autocomplete-input:focus').closest('.os2forms-dawa-address').length) {
// For DAWA address fields, return the entire value as a single value
return [ value.trim() ];
}
// For other fields, use the original behavior
return Drupal.autocomplete.splitValues(value);
};
})(jQuery, Drupal);
7 changes: 7 additions & 0 deletions modules/os2forms_dawa/os2forms_dawa.libraries.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dawa_address_autocomplete:
version: 1.x
js:
js/dawa_address_autocomplete.js: {}
dependencies:
- core/jquery
- core/drupal
11 changes: 11 additions & 0 deletions modules/os2forms_dawa/os2forms_dawa.module
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* OS2Forms Address autocomplete functionality module.
*/

use Drupal\Core\Form\FormStateInterface;

/**
* Implements hook_webform_migrate_d7_webform_element_ELEMENT_TYPE_alter().
*
Expand All @@ -26,3 +28,12 @@ function os2forms_dawa_webform_migrate_d7_webform_element_address_autocomp_alter
function os2forms_dawa_webform_migrate_d7_webform_element_addrs_autocomp_l_alter(&$markup, $indent, array $element) {
$markup .= "$indent '#type': os2forms_dawa_address_matrikula\n";
}

/**
* Implements hook_webform_element_alter().
*/
function os2forms_dawa_webform_element_alter(array &$element, FormStateInterface $form_state, array $context) {
if ('os2forms_dawa_address' === $element['#type']) {
$element['#attached']['library'][] = 'os2forms_dawa/dawa_address_autocomplete';
}
}
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.

Loading
Loading