diff --git a/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php b/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php index f61839e..4e28c53 100644 --- a/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php +++ b/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php @@ -120,13 +120,12 @@ class DefaultPluginManager extends PluginManagerBase implements PluginManagerInt * (optional) The name of the annotation that contains the plugin definition. * Defaults to 'Drupal\Component\Annotation\Plugin'. */ - public function __construct($subdir, \Traversable $namespaces, ModuleHandlerInterface $module_handler, $plugin_definition_annotation_name = 'Drupal\Component\Annotation\Plugin', $fallback_plugin_id = NULL) { + public function __construct($subdir, \Traversable $namespaces, ModuleHandlerInterface $module_handler, $plugin_definition_annotation_name = 'Drupal\Component\Annotation\Plugin') { $this->subdir = $subdir; $this->discovery = new AnnotatedClassDiscovery($subdir, $namespaces, $plugin_definition_annotation_name); $this->discovery = new ContainerDerivativeDiscoveryDecorator($this->discovery); $this->factory = new ContainerFactory($this); $this->moduleHandler = $module_handler; - $this->fallbackPluginId = $fallback_plugin_id; } /** @@ -171,6 +170,16 @@ protected function alterInfo($alter_hook) { } /** + * Sets the fallback plugin ID. + * + * @param string $fallback_plugin_id + * The plugin ID to be falled back to. + */ + public function setFallbackPluginId($fallback_plugin_id) { + $this->fallbackPluginId = $fallback_plugin_id; + } + + /** * {@inheritdoc} */ public function getDefinition($plugin_id) { @@ -291,7 +300,6 @@ protected function findDefinitions() { * {@inheritdoc} */ public function createInstance($plugin_id, array $configuration = array()) { - try { $instance = $this->factory->createInstance($plugin_id, $configuration); } @@ -319,7 +327,7 @@ public function createInstance($plugin_id, array $configuration = array()) { * @return string * The plugin ID of the fallback instance. */ - protected function getFallbackPluginId($original_plugin_id, $configuration) { + protected function getFallbackPluginId($original_plugin_id, array $configuration) { return $this->fallbackPluginId; } diff --git a/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php b/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php index 5c0d888..7bb996e 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php @@ -17,6 +17,9 @@ * Tests the DefaultPluginManager. * * @group Plugin + * @group Drupal + * + * @coversDefaultClass Drupal\Core\Plugin\DefaultPluginManager */ class DefaultPluginManagerTest extends UnitTestCase { @@ -72,6 +75,8 @@ protected function setUp() { /** * Tests the plugin manager with a disabled module. + * + * @covers ::getDefinition */ public function testDefaultPluginManagerWithDisabledModule() { $definitions = $this->expectedDefinitions; @@ -97,6 +102,9 @@ public function testDefaultPluginManagerWithDisabledModule() { /** * Tests the plugin manager with no cache and altering. + * + * @covers ::getDefinitions + * @covers ::getDefinition */ public function testDefaultPluginManager() { $plugin_manager = new TestPluginManager($this->namespaces, $this->expectedDefinitions); @@ -106,6 +114,9 @@ public function testDefaultPluginManager() { /** * Tests the plugin manager with no cache and altering. + * + * @covers ::getDefinitions + * @covers ::getDefinition */ public function testDefaultPluginManagerWithAlter() { $module_handler = $this->getMock('Drupal\Core\Extension\ModuleHandler'); @@ -124,6 +135,9 @@ public function testDefaultPluginManagerWithAlter() { /** * Tests the plugin manager with caching and altering. + * + * @covers ::getDefinitions + * @covers ::getDefinition */ public function testDefaultPluginManagerWithEmptyCache() { $cid = $this->randomName(); @@ -156,6 +170,8 @@ public function testDefaultPluginManagerWithEmptyCache() { /** * Tests the plugin manager with caching and altering. + * + * @covers ::getDefinitions */ public function testDefaultPluginManagerWithFilledCache() { $cid = $this->randomName(); @@ -186,6 +202,9 @@ public function testDefaultPluginManagerWithFilledCache() { /** * Tests the plugin manager cache clear with tags. + * + * @covers ::getFallbackPluginId + * @covers ::createInstance */ public function testCacheClearWithTags() { $cid = $this->randomName(); @@ -241,16 +260,17 @@ public function testCreateInstanceWithFallback() { $exception = new PluginException(); $factory->expects($this->at(0)) ->method('createInstance') - ->with('non_existing', array()) + ->with('non_existing', array('key' => 'value')) ->will($this->throwException($exception)); $factory->expects($this->at(1)) ->method('createInstance') - ->with('apple', array('_exception' => $exception)) + ->with('apple', array('_exception' => $exception, 'key' => 'value')) ->will($this->returnValue($apple)); - $plugin_manager = new TestPluginManager($this->namespaces, $this->expectedDefinitions, NULL, NULL, 'apple'); + $plugin_manager = new TestPluginManager($this->namespaces, $this->expectedDefinitions); + $plugin_manager->setFallbackPluginId('apple'); $plugin_manager->setFactory($factory); - $plugin = $plugin_manager->createInstance('non_existing'); + $plugin = $plugin_manager->createInstance('non_existing', array('key' => 'value')); $this->assertSame($apple, $plugin); } diff --git a/core/tests/Drupal/Tests/Core/Plugin/TestPluginManager.php b/core/tests/Drupal/Tests/Core/Plugin/TestPluginManager.php index e977b6e..4619640 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/TestPluginManager.php +++ b/core/tests/Drupal/Tests/Core/Plugin/TestPluginManager.php @@ -32,7 +32,7 @@ class TestPluginManager extends DefaultPluginManager { * @param string $fallback_plugin_id * (optional) The fallback plugin ID. */ - public function __construct(\Traversable $namespaces, array $definitions, ModuleHandlerInterface $module_handler = NULL, $alter_hook = NULL, $fallback_plugin_id = NULL) { + public function __construct(\Traversable $namespaces, array $definitions, ModuleHandlerInterface $module_handler = NULL, $alter_hook = NULL) { // Create the object that can be used to return definitions for all the // plugins available for this type. Most real plugin managers use a richer // discovery implementation, but StaticDiscovery lets us add some simple @@ -49,8 +49,6 @@ public function __construct(\Traversable $namespaces, array $definitions, Module if ($alter_hook) { $this->alterInfo($alter_hook); } - - $this->fallbackPluginId = $fallback_plugin_id; } /**