diff --git a/core/lib/Drupal/Core/Plugin/Discovery/AlterDecorator.php b/core/lib/Drupal/Core/Plugin/Discovery/AlterDecorator.php new file mode 100644 index 00000000000..d4ce40b0831 --- /dev/null +++ b/core/lib/Drupal/Core/Plugin/Discovery/AlterDecorator.php @@ -0,0 +1,69 @@ +decorated = $decorated; + $this->hook = $hook; + } + + /** + * Implements Drupal\Component\Plugin\Discovery\DiscoveryInterface::getDefinition(). + */ + public function getDefinition($plugin_id) { + $definitions = $this->getDefinitions(); + return isset($definitions[$plugin_id]) ? $definitions[$plugin_id] : NULL; + } + + + /** + * Implements Drupal\Component\Plugin\Discovery\DiscoveryInterface::getDefinitions(). + */ + public function getDefinitions() { + $definitions = $this->decorated->getDefinitions(); + drupal_alter($this->hook, $definitions); + return $definitions; + } + + /** + * Passes through all unknown calls onto the decorated object. + */ + public function __call($method, $args) { + return call_user_func_array(array($this->decorated, $method), $args); + } +} diff --git a/core/modules/system/tests/modules/plugin_test/lib/Drupal/plugin_test/Plugin/AlterDecoratorTestPluginManager.php b/core/modules/system/tests/modules/plugin_test/lib/Drupal/plugin_test/Plugin/AlterDecoratorTestPluginManager.php new file mode 100644 index 00000000000..2168b8beab6 --- /dev/null +++ b/core/modules/system/tests/modules/plugin_test/lib/Drupal/plugin_test/Plugin/AlterDecoratorTestPluginManager.php @@ -0,0 +1,20 @@ +discovery = new AlterDecorator($this->discovery, 'plugin_test'); + } +}