diff --git a/core/lib/Drupal/Component/Plugin/Discovery/ObjectDefinitionDiscoveryDecorator.php b/core/lib/Drupal/Component/Annotation/Plugin/Discovery/AnnotationBridgeDecorator.php similarity index 77% rename from core/lib/Drupal/Component/Plugin/Discovery/ObjectDefinitionDiscoveryDecorator.php rename to core/lib/Drupal/Component/Annotation/Plugin/Discovery/AnnotationBridgeDecorator.php index 985709c..53d70d1 100644 --- a/core/lib/Drupal/Component/Plugin/Discovery/ObjectDefinitionDiscoveryDecorator.php +++ b/core/lib/Drupal/Component/Annotation/Plugin/Discovery/AnnotationBridgeDecorator.php @@ -1,14 +1,14 @@ decorated = $decorated; @@ -48,6 +47,9 @@ public function __construct(DiscoveryInterface $decorated, $plugin_definition_an public function getDefinitions() { $definitions = $this->decorated->getDefinitions(); foreach ($definitions as $id => $definition) { + // Annotation constructors expect an array of values. If the definition is + // not an array, it usually means it has been processed already and can be + // ignored. if (is_array($definition)) { $definitions[$id] = (new $this->pluginDefinitionAnnotationName($definition))->get(); } diff --git a/core/lib/Drupal/Core/Layout/LayoutPluginManager.php b/core/lib/Drupal/Core/Layout/LayoutPluginManager.php index 23fa9f1..e1d0a1e 100644 --- a/core/lib/Drupal/Core/Layout/LayoutPluginManager.php +++ b/core/lib/Drupal/Core/Layout/LayoutPluginManager.php @@ -2,7 +2,7 @@ namespace Drupal\Core\Layout; -use Drupal\Component\Plugin\Discovery\ObjectDefinitionDiscoveryDecorator; +use Drupal\Component\Annotation\Plugin\Discovery\AnnotationBridgeDecorator; use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Extension\ModuleHandlerInterface; @@ -64,7 +64,7 @@ protected function getDiscovery() { if (!$this->discovery) { $discovery = new AnnotatedClassDiscovery($this->subdir, $this->namespaces, $this->pluginDefinitionAnnotationName, $this->additionalAnnotationNamespaces); $discovery = new YamlDiscoveryDecorator($discovery, 'layouts', $this->moduleHandler->getModuleDirectories() + $this->themeHandler->getThemeDirectories()); - $discovery = new ObjectDefinitionDiscoveryDecorator($discovery, $this->pluginDefinitionAnnotationName); + $discovery = new AnnotationBridgeDecorator($discovery, $this->pluginDefinitionAnnotationName); $discovery = new ObjectDefinitionContainerDerivativeDiscoveryDecorator($discovery); $this->discovery = $discovery; } diff --git a/core/tests/Drupal/Tests/Component/Annotation/Plugin/Discovery/AnnotationBridgeDecoratorTest.php b/core/tests/Drupal/Tests/Component/Annotation/Plugin/Discovery/AnnotationBridgeDecoratorTest.php new file mode 100644 index 0000000..c1e231e --- /dev/null +++ b/core/tests/Drupal/Tests/Component/Annotation/Plugin/Discovery/AnnotationBridgeDecoratorTest.php @@ -0,0 +1,61 @@ + 'foo']); + $definitions['array'] = ['id' => 'bar']; + $discovery = $this->prophesize(DiscoveryInterface::class); + $discovery->getDefinitions()->willReturn($definitions); + + $decorator = new AnnotationBridgeDecorator($discovery->reveal(), TestAnnotation::class); + + $expected = [ + 'object' => new ObjectDefinition(['id' => 'foo']), + 'array' => new ObjectDefinition(['id' => 'bar']), + ]; + $this->assertEquals($expected, $decorator->getDefinitions()); + } + +} + +class TestAnnotation extends Plugin { + + /** + * {@inheritdoc} + */ + public function get() { + return new ObjectDefinition($this->definition); + } + +} +class ObjectDefinition extends PluginDefinition { + + /** + * ObjectDefinition constructor. + * + * @param array $definition + */ + public function __construct(array $definition) { + foreach ($definition as $property => $value) { + $this->{$property} = $value; + } + } + +}