Skip to content

Commit

Permalink
Merge 9010468 into 6156dc3
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Oct 6, 2015
2 parents 6156dc3 + 9010468 commit a530c00
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
21 changes: 17 additions & 4 deletions src/Plugin/ContainerAwarePluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,23 @@
*/
class ContainerAwarePluginManager extends ContainerAware implements PluginManagerInterface {

/**
* The plugin manager definition.
*
* @var array
* The plugin manager definition.
*/
private $pluginManager = array();

/**
* Constructs a ContainerAwarePluginManager object.
*
* @param string $service_prefix
* The service prefix used to get the plugin instances from the container.
*/
public function __construct($service_prefix) {
public function __construct($service_prefix, $plugin_manager = array()) {
$this->servicePrefix = $service_prefix;
$this->pluginManager = $plugin_manager;
}

/**
Expand Down Expand Up @@ -59,8 +68,12 @@ public function hasDefinition($plugin_id) {
* {@inheritdoc}
*/
public function createInstance($plugin_id, array $configuration = array()) {
$plugin_definition_copy = $plugin_definition = $this->getDefinition($plugin_id);
$plugin_class = static::getPluginClass($plugin_id, $plugin_definition);
$plugin_definition = $this->getDefinition($plugin_id);
$plugin_definition['provider'] = isset($this->pluginManager['owner']) ? $this->pluginManager['owner'] : NULL;
$plugin_definition_copy = $plugin_definition;

$plugin_interface = isset($this->pluginManager['interface']) ? $this->pluginManager['interface'] : NULL;
$plugin_class = static::getPluginClass($plugin_id, $plugin_definition, $plugin_interface);

// If the plugin provides a factory method, pass the container to it.
if (is_subclass_of($plugin_class, 'Drupal\Core\Plugin\ContainerFactoryPluginInterface')) {
Expand Down Expand Up @@ -121,7 +134,7 @@ public static function getPluginClass($plugin_id, $plugin_definition = NULL, $re
}

if ($required_interface && !is_subclass_of($plugin_definition['class'], $required_interface)) {
throw new PluginException(sprintf('Plugin "%s" (%s) in %s should implement interface %s.', $plugin_id, $plugin_definition['class'], $plugin_definition['provider'], $required_interface));
throw new PluginException(sprintf('Plugin "%s" (%s) in %s must implement interface %s.', $plugin_id, $class, $plugin_definition['provider'], $required_interface));
}

return $class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ protected function getPluginManagerDefinition($name, $discovery_class, $plugin_m
$prefix = "$name.internal.";
return array(
'class' => '\Drupal\service_container\Plugin\ContainerAwarePluginManager',
'arguments' => array($prefix),
'arguments' => array($prefix, $plugin_manager),
'calls' => array(
array('setContainer', array('@service_container')),
),
Expand Down

0 comments on commit a530c00

Please sign in to comment.