-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into release/3.16.0
- Loading branch information
Showing
51 changed files
with
2,200 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
modules/os2forms_dawa/src/Entity/DatafordelerMatrikula.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
namespace Drupal\os2forms_dawa\Entity; | ||
|
||
/** | ||
* Class DatafordelerMatrikula. | ||
* | ||
* Wrapper class for Datafordeler matrikula object that easies | ||
* the matrikula property access. | ||
*/ | ||
class DatafordelerMatrikula { | ||
|
||
/** | ||
* Owner licence code / ejerlavskode. | ||
* | ||
* @var string | ||
*/ | ||
protected string $ownerLicenseCode; | ||
|
||
/** | ||
* Ownership name / ejerlavsnavn. | ||
* | ||
* @var string | ||
*/ | ||
protected string $ownershipName; | ||
|
||
|
||
/** | ||
* Matrikula number / matrikelnummer. | ||
* | ||
* @var string | ||
*/ | ||
protected string $matrikulaNumber; | ||
|
||
/** | ||
* DawaAddress constructor. | ||
* | ||
* Fills the property from the provided JSON metadata. | ||
* | ||
* @param array $json | ||
* Address properties as JSON metadata. | ||
*/ | ||
public function __construct(array $json) { | ||
$this->ownerLicenseCode = $json['properties']['ejerlavskode']; | ||
$this->ownershipName = $json['properties']['ejerlavsnavn']; | ||
$this->matrikulaNumber = $json['properties']['matrikelnummer']; | ||
} | ||
|
||
/** | ||
* Returns owner licence code. | ||
* | ||
* @return string | ||
* Owners licence code. | ||
*/ | ||
public function getOwnerLicenseCode(): string { | ||
return $this->ownerLicenseCode; | ||
} | ||
|
||
/** | ||
* Returns ownership name. | ||
* | ||
* @return string | ||
* ownership name. | ||
*/ | ||
public function getOwnershipName(): string { | ||
return $this->ownershipName; | ||
} | ||
|
||
/** | ||
* Returns makrikula number. | ||
* | ||
* @return string | ||
* Matrikula number | ||
*/ | ||
public function getMatrikulaNumber(): string { | ||
return $this->matrikulaNumber; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 144 additions & 0 deletions
144
modules/os2forms_dawa/src/Plugin/os2web/DataLookup/DatafordelerDataLookup.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
<?php | ||
|
||
namespace Drupal\os2forms_dawa\Plugin\os2web\DataLookup; | ||
|
||
use Drupal\Component\Utility\NestedArray; | ||
use Drupal\Core\Form\FormStateInterface; | ||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface; | ||
use Drupal\os2forms_dawa\Entity\DatafordelerMatrikula; | ||
use Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DataLookupBase; | ||
use GuzzleHttp\ClientInterface; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
|
||
/** | ||
* Defines a plugin for Datafordeler Data. | ||
* | ||
* @DataLookup( | ||
* id = "datafordeler_data_lookup", | ||
* label = @Translation("Datafordeler Address Lookup"), | ||
* ) | ||
*/ | ||
class DatafordelerDataLookup extends DataLookupBase implements DatafordelerDataLookupInterface, ContainerFactoryPluginInterface { | ||
|
||
/** | ||
* The HTTP client to fetch the feed data with. | ||
* | ||
* @var \GuzzleHttp\ClientInterface | ||
*/ | ||
protected $httpClient; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function __construct(array $configuration, $plugin_id, $plugin_definition, ClientInterface $httpClient) { | ||
$this->httpClient = $httpClient; | ||
parent::__construct($configuration, $plugin_id, $plugin_definition); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { | ||
return new static( | ||
$configuration, | ||
$plugin_id, | ||
$plugin_definition, | ||
$container->get('http_client'), | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getMatrikulaId(string $addressAccessId) : ?string { | ||
$url = "https://services.datafordeler.dk/DAR/DAR/3.0.0/rest/husnummerTilJordstykke"; | ||
|
||
$json = $this->httpClient->request('GET', $url, [ | ||
'query' => [ | ||
'husnummerid' => $addressAccessId, | ||
], | ||
])->getBody(); | ||
|
||
$jsonDecoded = json_decode($json, TRUE); | ||
if (is_array($jsonDecoded)) { | ||
if (NestedArray::keyExists($jsonDecoded, ['gældendeJordstykke', 'jordstykkeLokalId'])) { | ||
return NestedArray::getValue($jsonDecoded, ['gældendeJordstykke', 'jordstykkeLokalId']); | ||
} | ||
} | ||
|
||
return NULL; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getMatrikulaEntries(string $matrikulaId) : array { | ||
$matrikulaEntries = []; | ||
$url = "https://services.datafordeler.dk/Matriklen2/Matrikel/2.0.0/rest/SamletFastEjendom"; | ||
|
||
$configuration = $this->getConfiguration(); | ||
$json = $this->httpClient->request('GET', $url, [ | ||
'query' => [ | ||
'jordstykkeid' => $matrikulaId, | ||
'username' => $configuration['username'], | ||
'password' => $configuration['password'], | ||
], | ||
])->getBody(); | ||
|
||
$jsonDecoded = json_decode($json, TRUE); | ||
|
||
if (is_array($jsonDecoded)) { | ||
if (NestedArray::keyExists($jsonDecoded, ['features', 0, 'properties', 'jordstykke'])) { | ||
$jordstykker = NestedArray::getValue($jsonDecoded, ['features', 0, 'properties', 'jordstykke']); | ||
foreach ($jordstykker as $jordstyk) { | ||
$matrikulaEntries[] = new DatafordelerMatrikula($jordstyk); | ||
} | ||
} | ||
} | ||
|
||
return $matrikulaEntries; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function defaultConfiguration() { | ||
return [ | ||
'username' => '', | ||
'password' => '', | ||
] + parent::defaultConfiguration(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function buildConfigurationForm(array $form, FormStateInterface $form_state) { | ||
$form['username'] = [ | ||
'#type' => 'textfield', | ||
'#title' => $this->t('Username for service calls'), | ||
'#default_value' => $this->configuration['username'], | ||
'#required' => TRUE, | ||
'#description' => $this->t('Username required for performing API requests'), | ||
]; | ||
$form['password'] = [ | ||
'#type' => 'textfield', | ||
'#title' => $this->t('Password for service calls'), | ||
'#default_value' => $this->configuration['password'], | ||
'#required' => TRUE, | ||
'#description' => $this->t('Password required for performing API requests'), | ||
]; | ||
|
||
return $form; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { | ||
$configuration = $this->getConfiguration(); | ||
$configuration['username'] = $form_state->getValue('username'); | ||
$configuration['password'] = $form_state->getValue('password'); | ||
$this->setConfiguration($configuration); | ||
} | ||
|
||
} |
Oops, something went wrong.