Skip to content

Commit 5377bb2

Browse files
committed
Added preloading plugin configuration.
1 parent 77d01ae commit 5377bb2

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

os2web_datalookup.services.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
services:
22
plugin.manager.os2web_datalookup:
33
class: Drupal\os2web_datalookup\Plugin\DataLookupManager
4-
parent: default_plugin_manager
4+
arguments: ['@container.namespaces', '@cache.discovery', '@module_handler', '@config.factory']

src/Controller/DatalookupController.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Drupal\Component\Plugin\PluginManagerInterface;
66
use Drupal\Core\Controller\ControllerBase;
77
use Drupal\Core\Link;
8-
use Drupal\os2web_datalookup\Form\DataLookupPluginSettingsForm;
98
use Symfony\Component\DependencyInjection\ContainerInterface;
109

1110
/**
@@ -53,9 +52,7 @@ public function statusList() {
5352

5453
$rows = [];
5554
foreach ($this->manager->getDefinitions() as $id => $plugin_definition) {
56-
$configuration = $this->config(DataLookupPluginSettingsForm::getConfigName() . '.' . $id)->get();
57-
/** @var \Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DataLookupInterface $plugin */
58-
$plugin = $this->manager->createInstance($id, $configuration);
55+
$plugin = $this->manager->createInstance($id);
5956
$status = $plugin->getStatus();
6057
$rows[$id] = [
6158
'title' => $plugin_definition['label'],

src/Plugin/DataLookupManager.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
namespace Drupal\os2web_datalookup\Plugin;
44

5+
use Drupal\Core\Config\ConfigFactoryInterface;
56
use Drupal\Core\Plugin\DefaultPluginManager;
67
use Drupal\Core\Cache\CacheBackendInterface;
78
use Drupal\Core\Extension\ModuleHandlerInterface;
9+
use Drupal\os2web_datalookup\Form\DataLookupPluginSettingsForm;
810

911
/**
1012
* DataLookupManager plugin manager.
@@ -15,6 +17,13 @@
1517
*/
1618
class DataLookupManager extends DefaultPluginManager {
1719

20+
/**
21+
* The config factory.
22+
*
23+
* @var \Drupal\Core\Config\ConfigFactoryInterface
24+
*/
25+
protected $configFactory;
26+
1827
/**
1928
* Constructs an DataLookupManager object.
2029
*
@@ -25,8 +34,10 @@ class DataLookupManager extends DefaultPluginManager {
2534
* Cache backend instance to use.
2635
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
2736
* The module handler to invoke the alter hook with.
37+
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
38+
* The config factory.
2839
*/
29-
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
40+
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, ConfigFactoryInterface $config_factory) {
3041
parent::__construct(
3142
'Plugin/os2web/DataLookup',
3243
$namespaces,
@@ -36,6 +47,17 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac
3647

3748
$this->alterInfo('os2web_datalookup_info');
3849
$this->setCacheBackend($cache_backend, 'os2web_datalookup');
50+
$this->configFactory = $config_factory;
51+
}
52+
53+
/**
54+
* {@inheritdoc}
55+
*/
56+
public function createInstance($plugin_id, array $configuration = []) {
57+
if (empty($configuration)) {
58+
$configuration = $this->configFactory->get(DataLookupPluginSettingsForm::getConfigName() . '.' . $plugin_id)->get();
59+
}
60+
return parent::createInstance($plugin_id, $configuration);
3961
}
4062

4163
}

0 commit comments

Comments
 (0)