Skip to content

Commit f29ad65

Browse files
committed
OS2FORMS-359 SF1520 integration, Datalookup groups added
1 parent 882b3ad commit f29ad65

28 files changed

+1686
-3
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,20 @@ See [OS2Web git name convention](https://github.com/OS2Web/docs#git-guideline)
3636
### Using services in other modules
3737

3838
```
39+
// CVR lookup.
3940
\Drupal::service('plugin.manager.os2web_datalookup')->createInstance('serviceplatformen_cvr')->getLegalUnit('[CVR number]')
41+
42+
// CPR lookup.
43+
/** @var \Drupal\os2web_datalookup\Plugin\DataLookupManager $pluginManager */
44+
$pluginManager = \Drupal::service('plugin.manager.os2web_datalookup');
45+
/** @var \Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DataLookupCPRInterface $cprPlugin */
46+
$cprPlugin = $pluginManager->createDefaultInstanceByGroup('cpr_lookup');
47+
48+
if ($cprPlugin->isReady()) {
49+
$cprResult = $cprPlugin->lookup($cpr);
50+
}
51+
52+
// CPP lookup - DEPRECATED.
4053
\Drupal::service('plugin.manager.os2web_datalookup')->createInstance('serviceplatformen_cpr')->cprBasicInformation('[CPR number]'))
4154
```
4255

os2web_datalookup.links.task.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
os2web_datalookup.group_settings.all:
2+
title: 'All'
3+
route_name: os2web_datalookup.status_list
4+
base_route: os2web_datalookup.status_list
5+
os2web_datalookup.group_settings:
6+
deriver: 'Drupal\os2web_datalookup\Plugin\Derivative\GroupSettingsLocalTasks'
7+
weight: 100

src/Annotation/DataLookup.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,11 @@ class DataLookup extends Plugin {
4444
*/
4545
public $description = '';
4646

47+
/**
48+
* Group of the plugin lookup plugin.
49+
*
50+
* @var string
51+
*/
52+
public $group = '';
53+
4754
}

src/Controller/DatalookupController.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Drupal\Component\Plugin\PluginManagerInterface;
66
use Drupal\Core\Controller\ControllerBase;
77
use Drupal\Core\Link;
8+
use Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DataLookupInterface;
89
use Symfony\Component\DependencyInjection\ContainerInterface;
910

1011
/**
@@ -46,17 +47,21 @@ public function statusList() {
4647
->t('Title'),
4748
'status' => $this
4849
->t('Status'),
50+
'group' => $this
51+
->t('Group'),
4952
'action' => $this
5053
->t('Actions'),
5154
];
5255

5356
$rows = [];
5457
foreach ($this->manager->getDefinitions() as $id => $plugin_definition) {
58+
/** @var DataLookupInterface $plugin */
5559
$plugin = $this->manager->createInstance($id);
5660
$status = $plugin->getStatus();
5761
$rows[$id] = [
5862
'title' => $plugin_definition['label'],
5963
'status' => ($plugin->isReady() ? $this->t('READY') : $this->t('ERROR')) . ': ' . $status,
64+
'group' => $plugin_definition['group'],
6065
'action' => Link::createFromRoute($this->t('Settings'), "os2web_datalookup.$id"),
6166
];
6267
}
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<?php
2+
3+
namespace Drupal\os2web_datalookup\Form;
4+
5+
use Drupal\Component\Plugin\PluginManagerInterface;
6+
use Drupal\Core\Form\ConfigFormBase;
7+
use Drupal\Core\Form\FormStateInterface;
8+
use Drupal\Core\Link;
9+
use Symfony\Component\DependencyInjection\ContainerInterface;
10+
11+
/**
12+
* Form or configuring AuthProvider plugin.
13+
*/
14+
class DataLookupPluginGroupSettingsForm extends ConfigFormBase {
15+
16+
/**
17+
* Name of the config.
18+
*
19+
* @var string
20+
*/
21+
public static $configName = 'os2web_datalookup.groups.settings';
22+
23+
/** @var \Drupal\os2web_datalookup\Plugin\DataLookupManager */
24+
protected $dataLookupManager;
25+
26+
/**
27+
* Constructs a new DataLookupPluginGroupSettingsForm object.
28+
*
29+
* @param \Drupal\os2web_datalookup\Plugin\DataLookupManager
30+
* Datalookup manager.
31+
*/
32+
public function __construct(PluginManagerInterface $dataLookupManager) {
33+
$this->dataLookupManager = $dataLookupManager;
34+
}
35+
36+
/**
37+
* {@inheritdoc}
38+
*/
39+
public static function create(ContainerInterface $container) {
40+
return new static(
41+
$container->get('plugin.manager.os2web_datalookup')
42+
);
43+
}
44+
45+
/**
46+
* {@inheritdoc}
47+
*/
48+
public function getFormId() {
49+
return 'os2web_datalookop_group_settings_form_' . $this->getGroupIdFromRequest();
50+
}
51+
52+
/**
53+
* {@inheritdoc}
54+
*/
55+
protected function getEditableConfigNames() {
56+
return [DataLookupPluginGroupSettingsForm::$configName];
57+
}
58+
59+
/**
60+
* Returns the value of the param _plugin_id for the current request.
61+
*
62+
* @see \Drupal\os2web_nemlogin\Routing\AuthProviderRoutes
63+
*/
64+
protected function getGroupIdFromRequest() {
65+
$request = $this->getRequest();
66+
return $request->get('_group_id');
67+
}
68+
69+
/**
70+
* {@inheritdoc}
71+
*/
72+
public function buildForm(array $form, FormStateInterface $form_state) {
73+
$group_id = $this->getGroupIdFromRequest();
74+
75+
$plugin_definitions = $this->dataLookupManager->getDefinitionsByGroup($group_id);
76+
77+
$header = [
78+
'title' => $this
79+
->t('Title'),
80+
'status' => $this
81+
->t('Status'),
82+
'action' => $this
83+
->t('Actions'),
84+
];
85+
86+
$options = [];
87+
foreach ($plugin_definitions as $id => $plugin_definition) {
88+
/** @var \Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DataLookupInterface $plugin */
89+
$plugin = $this->dataLookupManager->createInstance($id);
90+
91+
$status = $plugin->getStatus();
92+
93+
$options[$plugin_definition['id']] = [
94+
'title' => $plugin_definition['label'],
95+
'status' => ($plugin->isReady() ? $this->t('READY') : $this->t('ERROR')) . ': ' . $status,
96+
'group' => $plugin_definition['group'],
97+
'action' => Link::createFromRoute($this->t('Settings'), "os2web_datalookup.$id"),
98+
];
99+
}
100+
101+
$form['default_plugin'] = [
102+
'#type' => 'tableselect',
103+
'#header' => $header,
104+
'#options' => $options,
105+
'#multiple' => FALSE,
106+
'#default_value' => $this->dataLookupManager->getGroupDefaultPlugin($group_id) ?? NULL,
107+
'#empty' => $this
108+
->t('No plugins found'),
109+
];
110+
111+
return parent::buildForm($form, $form_state);
112+
}
113+
114+
/**
115+
* {@inheritdoc}
116+
*/
117+
public function submitForm(array &$form, FormStateInterface $form_state) {
118+
$group_id = $this->getGroupIdFromRequest();
119+
120+
$config = $this->config(DataLookupPluginGroupSettingsForm::$configName);
121+
122+
$config->set("$group_id.default_plugin", $form_state->getValue('default_plugin'));
123+
$config->save();
124+
125+
parent::submitForm($form, $form_state);
126+
}
127+
128+
}

0 commit comments

Comments
 (0)