Skip to content

Commit f5be688

Browse files
committed
OS2FORMS-359 adding deprecated warning, hook update for CPR lookup default
1 parent f29ad65 commit f5be688

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

os2web_datalookup.install

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
use Drupal\os2web_datalookup\Form\DataLookupPluginGroupSettingsForm;
4+
5+
/**
6+
* Setting "serviceplatformen_cpr_extended" as default CPR lookup plugin.
7+
*/
8+
function os2web_datalookup_update_9001() {
9+
$config = \Drupal::service('config.factory')->getEditable(DataLookupPluginGroupSettingsForm::$configName);
10+
$config->set("cpr_lookup.default_plugin", 'serviceplatformen_cpr_extended');
11+
$config->save();
12+
}

src/Plugin/DataLookupManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function getDefinitionsByGroup($group_id) {
100100
}
101101

102102
/**
103-
* Returns groups of all existing Datalookup plugins.s
103+
* Returns groups of all existing Datalookup plugins.
104104
*
105105
* @return array
106106
* Array of groups, keyed by group_id.

src/Plugin/os2web/DataLookup/ServiceplatformenCPR.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s
9595
* [error] => Descriptive text shown when CPR doesn't validate
9696
*/
9797
public function cprBasicInformation($cpr) {
98+
\Drupal::logger('os2web_datalookup')->warning('"Serviceplatformen CPR (SF6008)" is obsolete and will be phased out. Please switch to "Serviceplatformen CPR - extended (SF1520)" as soon as possible');
99+
98100
$request = $this->prepareRequest();
99101
$request['PNR'] = str_replace('-', '', $cpr);
100102
return $this->query('callCPRBasicInformationService', $request);
@@ -128,6 +130,8 @@ public function validateCpr($cpr) {
128130
* [error] => Descriptive text if something goes wrong
129131
*/
130132
public function getAddress($cpr) {
133+
\Drupal::logger('os2web_datalookup')->notice('Calling \'getAddress()\' directly is deprecated, use DataLookupCPRInterface::lookup() method.');
134+
131135
$result = $this->cprBasicInformation($cpr);
132136

133137
// If all goes well we return address array.

src/Plugin/os2web/DataLookup/ServiceplatformenCPRExtended.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,34 @@
1616
* group = "cpr_lookup"
1717
* )
1818
*/
19-
class ServiceplatformenCPRExtended extends ServiceplatformenBase implements DataLookupCPRInterface{
19+
class ServiceplatformenCPRExtended extends ServiceplatformenBase implements DataLookupCPRInterface {
20+
21+
/**
22+
* {@inheritdoc}
23+
*/
24+
public function defaultConfiguration() {
25+
return array_merge(parent::defaultConfiguration(), [
26+
'test_mode_fixed_cpr' => '',
27+
]);
28+
}
2029

2130
/**
2231
* {@inheritdoc}
2332
*/
2433
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
2534
$form = parent::buildConfigurationForm($form, $form_state);
35+
$form['mode_fieldset']['test_mode_fixed_cpr'] = [
36+
'#type' => 'textfield',
37+
'#title' => $this->t('Fixed test CPR'),
38+
'#default_value' => $this->configuration['test_mode_fixed_cpr'],
39+
'#description' => $this->t('Fixed CPR that will be used for all requests to the serviceplatformen instead of the provided CPR.'),
40+
'#states' => [
41+
// Hide the settings when the cancel notify checkbox is disabled.
42+
'visible' => [
43+
'input[name="mode_selector"]' => ['value' => 1],
44+
],
45+
],
46+
];
2647
$form['test_cpr'] = [
2748
'#type' => 'textfield',
2849
'#title' => $this->t('Test CPR nr.'),
@@ -39,6 +60,7 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s
3960
if (!empty($form_state->getValue('test_cpr'))) {
4061
$cpr = $form_state->getValue('test_cpr');
4162
}
63+
4264
if (!empty($cpr)) {
4365
$cprResult = $this->lookup($cpr);
4466
$response = (array) $cprResult;
@@ -54,6 +76,14 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s
5476
* @inheritDoc
5577
*/
5678
public function lookup($cpr) {
79+
if ($this->configuration['mode_selector'] == 1 && $this->configuration['test_mode_fixed_cpr']) {
80+
$cpr = $this->configuration['test_mode_fixed_cpr'];
81+
\Drupal::messenger()->addMessage(
82+
$this->t("Test mode enabled, all CPR lookup requests are made against CPR: %cpr", ['%cpr' => $cpr]),
83+
MessengerInterface::TYPE_STATUS
84+
);
85+
}
86+
5787
$request = $this->prepareRequest();
5888
$request['PNR'] = str_replace('-', '', $cpr);
5989

@@ -63,6 +93,7 @@ public function lookup($cpr) {
6393
// If all goes well we return address array.
6494
if ($result['status']) {
6595
$cprResult->setSuccessful();
96+
$cprResult->setCpr($cpr);
6697
$persondata = $result['persondata'];
6798

6899
if ($persondata->navn) {

0 commit comments

Comments
 (0)