Skip to content

Commit d0472c4

Browse files
committed
Merge pull request #51 from drupol/Issue-2504031-Fix-__construct-of-plugins-to-be-compatible-with-Drupal-8
Issue #2504031: Fix __construct of plugins to be compatible with Drupal 8 and take the necessary configuration
2 parents 7f63d29 + b863b22 commit d0472c4

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/DependencyInjection/Container.php

+14
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,20 @@ public function has($id) {
225225
return isset($this->services[$id]) || isset($this->serviceDefinitions[$id]);
226226
}
227227

228+
/**
229+
* {@inheritdoc}
230+
*/
231+
public function createInstance($plugin_id, $service_definition) {
232+
$temporary_name = 'plugin_' . $plugin_id;
233+
$this->serviceDefinitions[$temporary_name] = $service_definition;
234+
235+
$plugin = $this->get($temporary_name);
236+
unset($this->serviceDefinitions[$temporary_name]);
237+
unset($this->services[$temporary_name]);
238+
239+
return $plugin;
240+
}
241+
228242
/**
229243
* {@inheritdoc}
230244
*/

src/Plugin/ContainerAwarePluginManager.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,15 @@ public function hasDefinition($plugin_id) {
5959
* {@inheritdoc}
6060
*/
6161
public function createInstance($plugin_id, array $configuration = array()) {
62-
// @todo: Use ->expandArguments() when get() disallows getting private
63-
// services.
64-
$plugin = clone $this->container->get($this->servicePrefix . $plugin_id);
65-
return $plugin;
62+
$plugin_definition = $this->getDefinition($plugin_id);
63+
$plugin_definition += array(
64+
'arguments' => array(),
65+
);
66+
67+
array_unshift($plugin_definition['arguments'], $plugin_id);
68+
array_unshift($plugin_definition['arguments'], $configuration);
69+
70+
return $this->container->createInstance($this->servicePrefix . $plugin_id, $plugin_definition);
6671
}
6772

6873
/**

0 commit comments

Comments
 (0)