diff --git a/core/lib/Drupal/Component/Plugin/PluginAwareInterface.php b/core/lib/Drupal/Component/Plugin/PluginAwareInterface.php index c67ec18..5506c9f 100644 --- a/core/lib/Drupal/Component/Plugin/PluginAwareInterface.php +++ b/core/lib/Drupal/Component/Plugin/PluginAwareInterface.php @@ -3,7 +3,7 @@ namespace Drupal\Component\Plugin; /** - * Interface for objects that are aware of a plugin. + * Provides an interface for objects that depend on a plugin. */ interface PluginAwareInterface { diff --git a/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php b/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php index fd1b13a..fa706a4 100644 --- a/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php +++ b/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php @@ -250,8 +250,8 @@ public function processDefinition(&$definition, $plugin_id) { // If no default form is defined and this plugin implements // \Drupal\Core\Plugin\PluginFormInterface, use that for the default form. - if (!isset($definition['form']['configuration']) && isset($definition['class']) && is_subclass_of($definition['class'], PluginFormInterface::class)) { - $definition['form']['configuration'] = $definition['class']; + if (!isset($definition['forms']['configure']) && isset($definition['class']) && is_subclass_of($definition['class'], PluginFormInterface::class)) { + $definition['forms']['configure'] = $definition['class']; } } diff --git a/core/lib/Drupal/Core/Plugin/PluginFormFactory.php b/core/lib/Drupal/Core/Plugin/PluginFormFactory.php index 4abb7ca..addd0cc 100644 --- a/core/lib/Drupal/Core/Plugin/PluginFormFactory.php +++ b/core/lib/Drupal/Core/Plugin/PluginFormFactory.php @@ -33,9 +33,9 @@ public function __construct(ClassResolverInterface $class_resolver) { * {@inheritdoc} */ public function createInstance(PluginInspectionInterface $plugin, $operation, $fallback_operation = NULL) { - if (!$this->hasFormClass($plugin, $operation)) { + if (!$this->hasForm($plugin, $operation)) { // Use the default form class if no form is specified for this operation. - if ($fallback_operation && $this->hasFormClass($plugin, $fallback_operation)) { + if ($fallback_operation && $this->hasForm($plugin, $fallback_operation)) { $operation = $fallback_operation; } else { @@ -68,8 +68,8 @@ public function createInstance(PluginInspectionInterface $plugin, $operation, $f /** * {@inheritdoc} */ - public function hasFormClass(PluginInspectionInterface $plugin, $operation) { - return isset($plugin->getPluginDefinition()['form'][$operation]); + public function hasForm(PluginInspectionInterface $plugin, $operation) { + return isset($plugin->getPluginDefinition()['forms'][$operation]); } /** @@ -83,8 +83,8 @@ public function hasFormClass(PluginInspectionInterface $plugin, $operation) { * @return null|string */ protected function getFormClass(PluginInspectionInterface $plugin, $operation) { - if ($this->hasFormClass($plugin, $operation)) { - return $plugin->getPluginDefinition()['form'][$operation]; + if ($this->hasForm($plugin, $operation)) { + return $plugin->getPluginDefinition()['forms'][$operation]; } } diff --git a/core/lib/Drupal/Core/Plugin/PluginFormFactoryInterface.php b/core/lib/Drupal/Core/Plugin/PluginFormFactoryInterface.php index a37fea8..b2e6b09 100644 --- a/core/lib/Drupal/Core/Plugin/PluginFormFactoryInterface.php +++ b/core/lib/Drupal/Core/Plugin/PluginFormFactoryInterface.php @@ -43,6 +43,6 @@ public function createInstance(PluginInspectionInterface $plugin, $operation, $f * @return bool * Returns TRUE if the plugin has a form for the operation. */ - public function hasFormClass(PluginInspectionInterface $plugin, $operation); + public function hasForm(PluginInspectionInterface $plugin, $operation); } diff --git a/core/lib/Drupal/Core/Plugin/PluginFormInterface.php b/core/lib/Drupal/Core/Plugin/PluginFormInterface.php index 577735f..397c98f 100644 --- a/core/lib/Drupal/Core/Plugin/PluginFormInterface.php +++ b/core/lib/Drupal/Core/Plugin/PluginFormInterface.php @@ -7,6 +7,10 @@ /** * Provides an interface for an embeddable plugin form. * + * Plugins can implement this form directly, or a standalone class can be used. + * Decoupled forms can implement \Drupal\Component\Plugin\PluginAwareInterface + * in order to gain access to the plugin. + * * @ingroup plugin_api */ interface PluginFormInterface { diff --git a/core/modules/block/src/BlockForm.php b/core/modules/block/src/BlockForm.php index d6d3014..03448b9 100644 --- a/core/modules/block/src/BlockForm.php +++ b/core/modules/block/src/BlockForm.php @@ -75,7 +75,7 @@ class BlockForm extends EntityForm { * * @var \Drupal\Core\Plugin\PluginFormFactoryInterface */ - protected $pluginFormManager; + protected $pluginFormFactory; /** * Constructs a BlockForm object. @@ -99,7 +99,7 @@ public function __construct(EntityManagerInterface $entity_manager, ExecutableMa $this->contextRepository = $context_repository; $this->language = $language; $this->themeHandler = $theme_handler; - $this->pluginFormManager = $plugin_form_manager; + $this->pluginFormFactory = $plugin_form_manager; } /** @@ -425,7 +425,7 @@ public function getUniqueMachineName(BlockInterface $block) { * The plugin form for the block. */ protected function getPluginForm(BlockPluginInterface $block) { - return $this->pluginFormManager->createInstance($block, 'configuration'); + return $this->pluginFormFactory->createInstance($block, 'configure'); } } diff --git a/core/modules/block/tests/src/Unit/BlockFormTest.php b/core/modules/block/tests/src/Unit/BlockFormTest.php index cb4bdc2..d8efe2b 100644 --- a/core/modules/block/tests/src/Unit/BlockFormTest.php +++ b/core/modules/block/tests/src/Unit/BlockFormTest.php @@ -60,7 +60,7 @@ class BlockFormTest extends UnitTestCase { * * @var \Drupal\Core\Plugin\PluginFormFactoryInterface|\Prophecy\Prophecy\ProphecyInterface */ - protected $pluginFormManager; + protected $pluginFormFactory; /** * {@inheritdoc} @@ -79,7 +79,7 @@ protected function setUp() { ->method('getStorage') ->will($this->returnValue($this->storage)); - $this->pluginFormManager = $this->prophesize(PluginFormFactoryInterface::class); + $this->pluginFormFactory = $this->prophesize(PluginFormFactoryInterface::class); } /** @@ -108,7 +108,7 @@ public function testGetUniqueMachineName() { ->method('getQuery') ->will($this->returnValue($query)); - $block_form_controller = new BlockForm($this->entityManager, $this->conditionManager, $this->contextRepository, $this->language, $this->themeHandler, $this->pluginFormManager->reveal()); + $block_form_controller = new BlockForm($this->entityManager, $this->conditionManager, $this->contextRepository, $this->language, $this->themeHandler, $this->pluginFormFactory->reveal()); // Ensure that the block with just one other instance gets the next available // name suggestion. diff --git a/core/tests/Drupal/KernelTests/Core/Block/MultipleBlockFormTest.php b/core/tests/Drupal/KernelTests/Core/Block/MultipleBlockFormTest.php index fcef32c..2fbe025 100644 --- a/core/tests/Drupal/KernelTests/Core/Block/MultipleBlockFormTest.php +++ b/core/tests/Drupal/KernelTests/Core/Block/MultipleBlockFormTest.php @@ -24,7 +24,7 @@ public function testMultipleForms() { $configuration = ['label' => 'A very cool block']; $block = \Drupal::service('plugin.manager.block')->createInstance('test_multiple_forms_block', $configuration); - $form_object1 = \Drupal::service('plugin_form.factory')->createInstance($block, 'configuration'); + $form_object1 = \Drupal::service('plugin_form.factory')->createInstance($block, 'configure'); $form_object2 = \Drupal::service('plugin_form.factory')->createInstance($block, 'secondary'); // Assert that the block itself is used for the default form. diff --git a/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php b/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php index 21f2031..feac004 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php @@ -383,14 +383,14 @@ public function providerTestProcessDefinition() { $data['no_form'][] = ['class' => TestPluginForm::class]; $data['no_form'][] = [ 'class' => TestPluginForm::class, - 'form' => ['configuration' => TestPluginForm::class], + 'forms' => ['configure' => TestPluginForm::class], 'foo' => ['bar' => ['baz']], ]; - $data['default_form'][] = ['class' => TestPluginForm::class, 'form' => ['configuration' => 'stdClass']]; + $data['default_form'][] = ['class' => TestPluginForm::class, 'forms' => ['configure' => 'stdClass']]; $data['default_form'][] = [ 'class' => TestPluginForm::class, - 'form' => ['configuration' => 'stdClass'], + 'forms' => ['configure' => 'stdClass'], 'foo' => ['bar' => ['baz']], ]; return $data; diff --git a/core/tests/Drupal/Tests/Core/Plugin/PluginFormFactoryTest.php b/core/tests/Drupal/Tests/Core/Plugin/PluginFormFactoryTest.php index 3e7f7f2..efd8920 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/PluginFormFactoryTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/PluginFormFactoryTest.php @@ -42,20 +42,20 @@ protected function setUp() { } /** - * @covers ::hasFormClass + * @covers ::hasForm */ - public function testHasFormClass() { + public function testHasForm() { $plugin_form = $this->prophesize(PluginFormInterface::class); $expected = $plugin_form->reveal(); $plugin = $this->prophesize(PluginInspectionInterface::class); $plugin->getPluginDefinition()->willReturn([ - 'form' => [ + 'forms' => [ 'standard_class' => get_class($expected), ], ]); - $result = $this->manager->hasFormClass($plugin->reveal(), 'standard_class'); + $result = $this->manager->hasForm($plugin->reveal(), 'standard_class'); $this->assertTrue($result); } @@ -70,7 +70,7 @@ public function testCreateInstance() { $plugin = $this->prophesize(PluginInspectionInterface::class); $plugin->getPluginDefinition()->willReturn([ - 'form' => [ + 'forms' => [ 'standard_class' => get_class($expected), ], ]); @@ -87,12 +87,12 @@ public function testCreateInstanceUsingPlugin() { $plugin = $this->prophesize(PluginInspectionInterface::class)->willImplement(PluginFormInterface::class); $plugin->getPluginDefinition()->willReturn([ - 'form' => [ - 'configuration' => get_class($plugin->reveal()), + 'forms' => [ + 'configure' => get_class($plugin->reveal()), ], ]); - $form_object = $this->manager->createInstance($plugin->reveal(), 'configuration'); + $form_object = $this->manager->createInstance($plugin->reveal(), 'configure'); $this->assertSame($plugin->reveal(), $form_object); } @@ -104,12 +104,12 @@ public function testCreateInstanceUsingPluginWithSlashes() { $plugin = $this->prophesize(PluginInspectionInterface::class)->willImplement(PluginFormInterface::class); $plugin->getPluginDefinition()->willReturn([ - 'form' => [ - 'configuration' => '\\' . get_class($plugin->reveal()), + 'forms' => [ + 'configure' => '\\' . get_class($plugin->reveal()), ], ]); - $form_object = $this->manager->createInstance($plugin->reveal(), 'configuration'); + $form_object = $this->manager->createInstance($plugin->reveal(), 'configure'); $this->assertSame($plugin->reveal(), $form_object); } @@ -121,7 +121,7 @@ public function testCreateInstanceDefaultFallback() { $plugin = $this->prophesize(PluginInspectionInterface::class)->willImplement(PluginFormInterface::class); $plugin->getPluginDefinition()->willReturn([ - 'form' => [ + 'forms' => [ 'fallback' => get_class($plugin->reveal()), ], ]); @@ -142,7 +142,7 @@ public function testCreateInstancePluginAware() { $plugin = $this->prophesize(PluginInspectionInterface::class); $plugin->getPluginDefinition()->willReturn([ - 'form' => [ + 'forms' => [ 'operation_aware' => get_class($expected), ], ]); @@ -179,7 +179,7 @@ public function testCreateInstanceInvalidException() { $plugin = $this->prophesize(PluginInspectionInterface::class); $plugin->getPluginId()->willReturn('the_plugin_id'); $plugin->getPluginDefinition()->willReturn([ - 'form' => [ + 'forms' => [ 'invalid' => get_class($expected), ], ]);