diff --git a/core/lib/Drupal/Component/Plugin/Definition/PluginDefinitionProviderInterface.php b/core/lib/Drupal/Component/Plugin/Definition/PluginDefinitionProviderInterface.php index ff64ff7..744b792 100644 --- a/core/lib/Drupal/Component/Plugin/Definition/PluginDefinitionProviderInterface.php +++ b/core/lib/Drupal/Component/Plugin/Definition/PluginDefinitionProviderInterface.php @@ -3,7 +3,7 @@ namespace Drupal\Component\Plugin\Definition; /** - * @deprecated Combine with \Drupal\Component\Plugin\Definition\PluginDefinitionInterface in Drupal 9. + * @todo Move to \Drupal\Component\Plugin\Definition\PluginDefinitionInterface. */ interface PluginDefinitionProviderInterface extends PluginDefinitionInterface { diff --git a/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php b/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php index ffdac5a..d055ba4 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\Core\Plugin; +use Drupal\Component\Plugin\Definition\PluginDefinitionProviderInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\PluginFormInterface; @@ -360,6 +361,32 @@ public function testGetCacheMaxAge() { } /** + * @covers ::findDefinitions + * @covers ::extractProviderFromDefinition + */ + public function testProviderExists() { + $definitions = []; + $definitions['array_based_found'] = ['provider' => 'module_found']; + $definitions['array_based_missing'] = ['provider' => 'module_missing']; + $definitions['stdclass_based_found'] = (object) ['provider' => 'module_found']; + $definitions['stdclass_based_missing'] = (object) ['provider' => 'module_missing']; + $definitions['classed_object_found'] = new ObjectDefinition(['provider' => 'module_found']); + $definitions['classed_object_missing'] = new ObjectDefinition(['provider' => 'module_missing']); + + $expected = []; + $expected['array_based_found'] = $definitions['array_based_found']; + $expected['stdclass_based_found'] = $definitions['stdclass_based_found']; + $expected['classed_object_found'] = $definitions['classed_object_found']; + + $module_handler = $this->prophesize(ModuleHandlerInterface::class); + $module_handler->moduleExists('module_found')->willReturn(TRUE)->shouldBeCalled(); + $module_handler->moduleExists('module_missing')->willReturn(FALSE)->shouldBeCalled(); + $plugin_manager = new TestPluginManager($this->namespaces, $definitions, $module_handler->reveal()); + $result = $plugin_manager->getDefinitions(); + $this->assertEquals($expected, $result); + } + + /** * @covers ::processDefinition * @dataProvider providerTestProcessDefinition */ @@ -453,3 +480,49 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s } } +class ObjectDefinition implements PluginDefinitionProviderInterface { + + /** + * @var string + */ + protected $class; + + /** + * @var string + */ + protected $provider; + + /** + * ObjectDefinition constructor. + * + * @param array $definition + */ + public function __construct(array $definition) { + foreach ($definition as $property => $value) { + $this->{$property} = $value; + } + } + + /** + * {@inheritdoc} + */ + public function setClass($class) { + $this->class = $class; + return $this; + } + + /** + * {@inheritdoc} + */ + public function getClass() { + return $this->class; + } + + /** + * {@inheritdoc} + */ + public function getProvider() { + return $this->provider; + } + +}