3 namespace Drupal\Tests\Core\Plugin;
5 use Drupal\Component\Plugin\Discovery\StaticDiscovery;
6 use Drupal\Component\Plugin\Factory\DefaultFactory;
7 use Drupal\Core\Extension\ModuleHandlerInterface;
8 use Drupal\Core\Plugin\DefaultPluginManager;
11 * A plugin manager for condition plugins.
13 class TestPluginManager extends DefaultPluginManager {
16 * Constructs a TestPluginManager object.
18 * @param \Traversable $namespaces
19 * An object that implements \Traversable which contains the root paths
20 * keyed by the corresponding namespace to look for plugin implementations.
21 * @param array $definitions
22 * An array of static definitions.
23 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
24 * (optional) The module handler to invoke the alter hook with.
25 * @param string $alter_hook
26 * (optional) Name of the alter hook.
27 * @param string $interface
28 * (optional) The interface required for the plugins.
30 public function __construct(\Traversable $namespaces, array $definitions, ModuleHandlerInterface $module_handler = NULL, $alter_hook = NULL, $interface = NULL) {
31 // Create the object that can be used to return definitions for all the
32 // plugins available for this type. Most real plugin managers use a richer
33 // discovery implementation, but StaticDiscovery lets us add some simple
34 // mock plugins for unit testing.
35 $this->discovery = new StaticDiscovery();
36 $this->factory = new DefaultFactory($this->discovery, $interface);
38 // Add the static definitions.
39 foreach ($definitions as $key => $definition) {
40 $this->discovery->setDefinition($key, $definition);
43 $this->moduleHandler = $module_handler;
46 $this->alterInfo($alter_hook);