diff --git a/core/core.services.yml b/core/core.services.yml index 09eedda..1f2b069 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -569,8 +569,8 @@ services: entity.autocomplete_matcher: class: Drupal\Core\Entity\EntityAutocompleteMatcher arguments: ['@plugin.manager.entity_reference_selection'] - plugin_form.manager: - class: Drupal\Core\Plugin\PluginFormManager + plugin_form.factory: + class: Drupal\Core\Plugin\PluginFormFactory arguments: ['@class_resolver'] plugin.manager.entity_reference_selection: class: Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManager diff --git a/core/lib/Drupal/Component/Plugin/PluginAwareInterface.php b/core/lib/Drupal/Component/Plugin/PluginAwareInterface.php index 154aab2..c67ec18 100644 --- a/core/lib/Drupal/Component/Plugin/PluginAwareInterface.php +++ b/core/lib/Drupal/Component/Plugin/PluginAwareInterface.php @@ -10,9 +10,9 @@ /** * Sets the plugin for this object. * - * @param object $plugin + * @param \Drupal\Component\Plugin\PluginInspectionInterface $plugin * The plugin. */ - public function setPlugin($plugin); + public function setPlugin(PluginInspectionInterface $plugin); } diff --git a/core/lib/Drupal/Core/Block/BlockManager.php b/core/lib/Drupal/Core/Block/BlockManager.php index 036933f..3c88bdc 100644 --- a/core/lib/Drupal/Core/Block/BlockManager.php +++ b/core/lib/Drupal/Core/Block/BlockManager.php @@ -8,7 +8,6 @@ use Drupal\Core\Plugin\CategorizingPluginManagerTrait; use Drupal\Core\Plugin\Context\ContextAwarePluginManagerTrait; use Drupal\Core\Plugin\DefaultPluginManager; -use Drupal\Core\Plugin\PluginFormInterface; /** * Manages discovery and instantiation of block plugins. @@ -49,12 +48,6 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac public function processDefinition(&$definition, $plugin_id) { parent::processDefinition($definition, $plugin_id); $this->processDefinitionCategory($definition); - - // If no default form is defined and this plugin implements - // \Drupal\Core\Plugin\PluginFormInterface, use that for the default form. - if (!isset($definition['form']['default']) && is_subclass_of($definition['class'], PluginFormInterface::class)) { - $definition['form']['default'] = $definition['class']; - } } /** diff --git a/core/lib/Drupal/Core/Form/OperationAwareFormInterface.php b/core/lib/Drupal/Core/Form/OperationAwareFormInterface.php deleted file mode 100644 index 8172bd7..0000000 --- a/core/lib/Drupal/Core/Form/OperationAwareFormInterface.php +++ /dev/null @@ -1,20 +0,0 @@ -plugin = $plugin; + } + + /** + * {@inheritdoc} + */ + public function validateConfigurationForm(array &$form, FormStateInterface $form_state) { + // Validation is optional. + } + +} diff --git a/core/lib/Drupal/Core/Plugin/PluginFormManager.php b/core/lib/Drupal/Core/Plugin/PluginFormFactory.php similarity index 79% rename from core/lib/Drupal/Core/Plugin/PluginFormManager.php rename to core/lib/Drupal/Core/Plugin/PluginFormFactory.php index b786e65..9c6e88e 100644 --- a/core/lib/Drupal/Core/Plugin/PluginFormManager.php +++ b/core/lib/Drupal/Core/Plugin/PluginFormFactory.php @@ -6,12 +6,11 @@ use Drupal\Component\Plugin\PluginAwareInterface; use Drupal\Component\Plugin\PluginInspectionInterface; use Drupal\Core\DependencyInjection\ClassResolverInterface; -use Drupal\Core\Form\OperationAwareFormInterface; /** * Provides form discovery capabilities for plugins. */ -class PluginFormManager implements PluginFormManagerInterface { +class PluginFormFactory implements PluginFormFactoryInterface { /** * The class resolver. @@ -21,9 +20,10 @@ class PluginFormManager implements PluginFormManagerInterface { protected $classResolver; /** - * PluginFormManager constructor. + * PluginFormFactory constructor. * * @param \Drupal\Core\DependencyInjection\ClassResolverInterface $class_resolver + * The class resolver. */ public function __construct(ClassResolverInterface $class_resolver) { $this->classResolver = $class_resolver; @@ -32,11 +32,7 @@ public function __construct(ClassResolverInterface $class_resolver) { /** * {@inheritdoc} */ - public function getFormObject($plugin, $operation, $fallback_operation = NULL) { - if (!$plugin instanceof PluginInspectionInterface) { - throw new \InvalidArgumentException(sprintf('The plugin must implement "%s"', PluginInspectionInterface::class)); - } - + public function createInstance(PluginInspectionInterface $plugin, $operation, $fallback_operation = NULL) { $definition = $plugin->getPluginDefinition(); if (!isset($definition['form'][$operation])) { // Use the default form class if no form is specified for this operation. @@ -65,10 +61,6 @@ public function getFormObject($plugin, $operation, $fallback_operation = NULL) { $form_object->setPlugin($plugin); } - if ($form_object instanceof OperationAwareFormInterface) { - $form_object->setOperation($operation); - } - return $form_object; } diff --git a/core/lib/Drupal/Core/Plugin/PluginFormManagerInterface.php b/core/lib/Drupal/Core/Plugin/PluginFormFactoryInterface.php similarity index 76% rename from core/lib/Drupal/Core/Plugin/PluginFormManagerInterface.php rename to core/lib/Drupal/Core/Plugin/PluginFormFactoryInterface.php index 9e3bf35..d5c6818 100644 --- a/core/lib/Drupal/Core/Plugin/PluginFormManagerInterface.php +++ b/core/lib/Drupal/Core/Plugin/PluginFormFactoryInterface.php @@ -2,6 +2,8 @@ namespace Drupal\Core\Plugin; +use Drupal\Component\Plugin\PluginInspectionInterface; + /** * Provides an interface for retrieving form objects for plugins. * @@ -11,12 +13,12 @@ * implement \Drupal\Component\Plugin\PluginAwareInterface in order to gain * access to the plugin. */ -interface PluginFormManagerInterface { +interface PluginFormFactoryInterface { /** * Creates a new form instance. * - * @param object $plugin + * @param \Drupal\Component\Plugin\PluginInspectionInterface $plugin * The plugin the form is for. * @param string $operation * The name of the operation to use, e.g., 'add' or 'edit'. @@ -28,6 +30,6 @@ * * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException */ - public function getFormObject($plugin, $operation, $fallback_operation = NULL); + public function createInstance(PluginInspectionInterface $plugin, $operation, $fallback_operation = NULL); } diff --git a/core/modules/block/src/BlockForm.php b/core/modules/block/src/BlockForm.php index e9d03fc..bd1366f 100644 --- a/core/modules/block/src/BlockForm.php +++ b/core/modules/block/src/BlockForm.php @@ -3,7 +3,7 @@ namespace Drupal\block; use Drupal\Component\Utility\Html; -use Drupal\Core\Plugin\PluginFormManagerInterface; +use Drupal\Core\Plugin\PluginFormFactoryInterface; use Drupal\Core\Block\BlockPluginInterface; use Drupal\Core\Entity\EntityForm; use Drupal\Core\Entity\EntityManagerInterface; @@ -71,11 +71,11 @@ class BlockForm extends EntityForm { protected $contextRepository; /** - * The plugin form manager. + * The plugin form factory. * - * @var \Drupal\Core\Plugin\PluginFormManagerInterface + * @var \Drupal\Core\Plugin\PluginFormFactoryInterface */ - protected $pluginFormManager; + protected $pluginFormFactory; /** * Constructs a BlockForm object. @@ -90,16 +90,16 @@ class BlockForm extends EntityForm { * The language manager. * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler * The theme handler. - * @param \Drupal\Core\Plugin\PluginFormManagerInterface $plugin_form_manager - * The plugin form manager. + * @param \Drupal\Core\Plugin\PluginFormFactoryInterface $plugin_form_factory + * The plugin form factory. */ - public function __construct(EntityManagerInterface $entity_manager, ExecutableManagerInterface $manager, ContextRepositoryInterface $context_repository, LanguageManagerInterface $language, ThemeHandlerInterface $theme_handler, PluginFormManagerInterface $plugin_form_manager) { + public function __construct(EntityManagerInterface $entity_manager, ExecutableManagerInterface $manager, ContextRepositoryInterface $context_repository, LanguageManagerInterface $language, ThemeHandlerInterface $theme_handler, PluginFormFactoryInterface $plugin_form_factory) { $this->storage = $entity_manager->getStorage('block'); $this->manager = $manager; $this->contextRepository = $context_repository; $this->language = $language; $this->themeHandler = $theme_handler; - $this->pluginFormManager = $plugin_form_manager; + $this->pluginFormFactory = $plugin_form_factory; } /** @@ -112,7 +112,7 @@ public static function create(ContainerInterface $container) { $container->get('context.repository'), $container->get('language_manager'), $container->get('theme_handler'), - $container->get('plugin_form.manager') + $container->get('plugin_form.factory') ); } @@ -435,7 +435,7 @@ public function getUniqueMachineName(BlockInterface $block) { * The plugin form for the block. */ protected function getPluginForm(BlockPluginInterface $block) { - return $this->pluginFormManager->getFormObject($block, 'default'); + return $this->pluginFormFactory->createInstance($block, 'configuration'); } } diff --git a/core/modules/block/tests/modules/block_test/src/Form/EmptyBlockForm.php b/core/modules/block/tests/modules/block_test/src/Form/EmptyBlockForm.php index 6d3a9b8..98c6fc5 100644 --- a/core/modules/block/tests/modules/block_test/src/Form/EmptyBlockForm.php +++ b/core/modules/block/tests/modules/block_test/src/Form/EmptyBlockForm.php @@ -3,31 +3,12 @@ namespace Drupal\block_test\Form; use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Form\OperationAwareFormInterface; -use Drupal\Component\Plugin\PluginAwareInterface; -use Drupal\Core\Plugin\PluginFormInterface; +use Drupal\Core\Plugin\PluginFormBase; /** * Provides a form for a block that is empty. */ -class EmptyBlockForm implements PluginAwareInterface, PluginFormInterface, OperationAwareFormInterface { - - /** - * @var string - */ - protected $operation; - - /** - * @var object - */ - protected $plugin; - - /** - * {@inheritdoc} - */ - public function setOperation($operation) { - $this->operation = $operation; - } +class EmptyBlockForm extends PluginFormBase { /** * {@inheritdoc} @@ -39,22 +20,8 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta /** * {@inheritdoc} */ - public function validateConfigurationForm(array &$form, FormStateInterface $form_state) { - // Intentionally empty. - } - - /** - * {@inheritdoc} - */ public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { // Intentionally empty. } - /** - * {@inheritdoc} - */ - public function setPlugin($plugin) { - $this->plugin = $plugin; - } - } diff --git a/core/modules/block/tests/src/Unit/BlockFormTest.php b/core/modules/block/tests/src/Unit/BlockFormTest.php index 07b3780..9d81555 100644 --- a/core/modules/block/tests/src/Unit/BlockFormTest.php +++ b/core/modules/block/tests/src/Unit/BlockFormTest.php @@ -3,7 +3,7 @@ namespace Drupal\Tests\block\Unit; use Drupal\block\BlockForm; -use Drupal\Core\Plugin\PluginFormManagerInterface; +use Drupal\Core\Plugin\PluginFormFactoryInterface; use Drupal\Tests\UnitTestCase; /** @@ -56,11 +56,11 @@ class BlockFormTest extends UnitTestCase { protected $contextRepository; /** - * The plugin form manager. + * The plugin form factory. * - * @var \Drupal\Core\Plugin\PluginFormManagerInterface|\Prophecy\Prophecy\ProphecyInterface + * @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(PluginFormManagerInterface::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/modules/outside_in/src/Block/BlockEntityOffCanvasForm.php b/core/modules/outside_in/src/Block/BlockEntityOffCanvasForm.php index 7f5c868..56ceba4 100644 --- a/core/modules/outside_in/src/Block/BlockEntityOffCanvasForm.php +++ b/core/modules/outside_in/src/Block/BlockEntityOffCanvasForm.php @@ -68,7 +68,7 @@ protected function submitVisibility(array $form, FormStateInterface $form_state) * {@inheritdoc} */ protected function getPluginForm(BlockPluginInterface $block) { - return $this->pluginFormManager->getFormObject($block, 'offcanvas', 'default'); + return $this->pluginFormFactory->createInstance($block, 'offcanvas', 'configuration'); } } diff --git a/core/modules/outside_in/src/Form/SystemBrandingOffCanvasForm.php b/core/modules/outside_in/src/Form/SystemBrandingOffCanvasForm.php index 13f037c..6e71c76 100644 --- a/core/modules/outside_in/src/Form/SystemBrandingOffCanvasForm.php +++ b/core/modules/outside_in/src/Form/SystemBrandingOffCanvasForm.php @@ -2,12 +2,10 @@ namespace Drupal\outside_in\Form; - -use Drupal\Component\Plugin\PluginAwareInterface; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Plugin\PluginFormInterface; +use Drupal\Core\Plugin\PluginFormBase; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -15,7 +13,7 @@ * * @see outside_in_block_alter() */ -class SystemBrandingOffCanvasForm implements ContainerInjectionInterface, PluginAwareInterface, PluginFormInterface { +class SystemBrandingOffCanvasForm extends PluginFormBase implements ContainerInjectionInterface { /** * The plugin. @@ -53,13 +51,6 @@ public static function create(ContainerInterface $container) { /** * {@inheritdoc} */ - public function setPlugin($plugin) { - $this->plugin = $plugin; - } - - /** - * {@inheritdoc} - */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $form = $this->plugin->buildConfigurationForm($form, $form_state); diff --git a/core/modules/outside_in/src/Form/SystemMenuOffCanvasForm.php b/core/modules/outside_in/src/Form/SystemMenuOffCanvasForm.php index 997d7a8..627d42e 100644 --- a/core/modules/outside_in/src/Form/SystemMenuOffCanvasForm.php +++ b/core/modules/outside_in/src/Form/SystemMenuOffCanvasForm.php @@ -2,12 +2,12 @@ namespace Drupal\outside_in\Form; -use Drupal\Component\Plugin\PluginAwareInterface; +use Drupal\Component\Plugin\PluginInspectionInterface; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Plugin\PluginFormInterface; +use Drupal\Core\Plugin\PluginFormBase; use Drupal\Core\Render\Element; use Drupal\Core\Routing\RedirectDestinationTrait; use Drupal\Core\StringTranslation\StringTranslationTrait; @@ -20,7 +20,7 @@ * * @see outside_in_block_alter() */ -class SystemMenuOffCanvasForm implements ContainerInjectionInterface, PluginAwareInterface, PluginFormInterface { +class SystemMenuOffCanvasForm extends PluginFormBase implements ContainerInjectionInterface { use StringTranslationTrait; use RedirectDestinationTrait; @@ -116,7 +116,11 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s /** * Gets the entity form for this menu. * - * @return \Drupal\Core\Form\FormInterface + * @param \Drupal\system\MenuInterface $entity + * The menu entity. + * + * @return \Drupal\Core\Entity\EntityFormInterface + * The entity form. */ protected function getEntityForm(MenuInterface $entity) { $entity_form = $this->entityTypeManager->getFormObject('menu', 'edit'); @@ -145,12 +149,9 @@ protected function ensureFormState(FormStateInterface $form_state) { } /** - * Sets the plugin for this object. - * - * @param object $plugin - * The plugin. + * {@inheritdoc} */ - public function setPlugin($plugin) { + public function setPlugin(PluginInspectionInterface $plugin) { $this->plugin = $plugin; $this->entity = $this->menuStorage->load($this->plugin->getDerivativeId()); } diff --git a/core/tests/Drupal/KernelTests/Core/Block/MultipleBlockFormTest.php b/core/tests/Drupal/KernelTests/Core/Block/MultipleBlockFormTest.php index fa8b74a..08dfa75 100644 --- a/core/tests/Drupal/KernelTests/Core/Block/MultipleBlockFormTest.php +++ b/core/tests/Drupal/KernelTests/Core/Block/MultipleBlockFormTest.php @@ -24,17 +24,15 @@ 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.manager')->getFormObject($block, 'default'); - $form_object2 = \Drupal::service('plugin_form.manager')->getFormObject($block, 'secondary'); + $form_object1 = \Drupal::service('plugin_form.factory')->createInstance($block, 'configuration'); + $form_object2 = \Drupal::service('plugin_form.factory')->createInstance($block, 'secondary'); // Assert that the block itself is used for the default form. $this->assertSame($block, $form_object1); - // Ensure that EmptyBlockForm is used and the plugin and operation are set. - $expected_secondary = new EmptyBlockForm(); - $expected_secondary->setOperation('secondary'); - $expected_secondary->setPlugin($block); - $this->assertEquals($expected_secondary, $form_object2); + // Ensure that EmptyBlockForm is used and the plugin is set. + $this->assertInstanceOf(EmptyBlockForm::class, $form_object2); + $this->assertAttributeEquals($block, 'plugin', $form_object2); } } diff --git a/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php b/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php index 55474c5..21f2031 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' => ['default' => TestPluginForm::class], + 'form' => ['configuration' => TestPluginForm::class], 'foo' => ['bar' => ['baz']], ]; - $data['default_form'][] = ['class' => TestPluginForm::class, 'form' => ['default' => 'stdClass']]; + $data['default_form'][] = ['class' => TestPluginForm::class, 'form' => ['configuration' => 'stdClass']]; $data['default_form'][] = [ 'class' => TestPluginForm::class, - 'form' => ['default' => 'stdClass'], + 'form' => ['configuration' => 'stdClass'], 'foo' => ['bar' => ['baz']], ]; return $data; diff --git a/core/tests/Drupal/Tests/Core/Plugin/PluginFormManagerTest.php b/core/tests/Drupal/Tests/Core/Plugin/PluginFormFactoryTest.php similarity index 60% rename from core/tests/Drupal/Tests/Core/Plugin/PluginFormManagerTest.php rename to core/tests/Drupal/Tests/Core/Plugin/PluginFormFactoryTest.php index bd77f0b..e9879dc 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/PluginFormManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/PluginFormFactoryTest.php @@ -7,16 +7,15 @@ use Drupal\Component\Plugin\PluginInspectionInterface; use Drupal\Core\DependencyInjection\ClassResolverInterface; use Drupal\Core\Plugin\PluginFormInterface; -use Drupal\Core\Form\OperationAwareFormInterface; -use Drupal\Core\Plugin\PluginFormManager; +use Drupal\Core\Plugin\PluginFormFactory; use Drupal\Tests\UnitTestCase; use Prophecy\Argument; /** - * @coversDefaultClass \Drupal\Core\Plugin\PluginFormManager + * @coversDefaultClass \Drupal\Core\Plugin\PluginFormFactory * @group Plugin */ -class PluginFormManagerTest extends UnitTestCase { +class PluginFormFactoryTest extends UnitTestCase { /** * The class resolver. @@ -28,7 +27,7 @@ class PluginFormManagerTest extends UnitTestCase { /** * The manager being tested. * - * @var \Drupal\Core\Plugin\PluginFormManager + * @var \Drupal\Core\Plugin\PluginFormFactory */ protected $manager; @@ -39,13 +38,13 @@ protected function setUp() { parent::setUp(); $this->classResolver = $this->prophesize(ClassResolverInterface::class); - $this->manager = new PluginFormManager($this->classResolver->reveal()); + $this->manager = new PluginFormFactory($this->classResolver->reveal()); } /** - * @covers ::getFormObject + * @covers ::createInstance */ - public function testGetFormObject() { + public function testCreateInstance() { $plugin_form = $this->prophesize(PluginFormInterface::class); $expected = $plugin_form->reveal(); @@ -58,31 +57,31 @@ public function testGetFormObject() { ], ]); - $form_object = $this->manager->getFormObject($plugin->reveal(), 'standard_class'); + $form_object = $this->manager->createInstance($plugin->reveal(), 'standard_class'); $this->assertSame($expected, $form_object); } /** - * @covers ::getFormObject + * @covers ::createInstance */ - public function testGetFormObjectUsingPlugin() { + public function testCreateInstanceUsingPlugin() { $this->classResolver->getInstanceFromDefinition(Argument::cetera())->shouldNotBeCalled(); $plugin = $this->prophesize(PluginInspectionInterface::class)->willImplement(PluginFormInterface::class); $plugin->getPluginDefinition()->willReturn([ 'form' => [ - 'default' => get_class($plugin->reveal()), + 'configuration' => get_class($plugin->reveal()), ], ]); - $form_object = $this->manager->getFormObject($plugin->reveal(), 'default'); + $form_object = $this->manager->createInstance($plugin->reveal(), 'configuration'); $this->assertSame($plugin->reveal(), $form_object); } /** - * @covers ::getFormObject + * @covers ::createInstance */ - public function testGetFormObjectDefaultFallback() { + public function testCreateInstanceDefaultFallback() { $this->classResolver->getInstanceFromDefinition(Argument::cetera())->shouldNotBeCalled(); $plugin = $this->prophesize(PluginInspectionInterface::class)->willImplement(PluginFormInterface::class); @@ -92,36 +91,14 @@ public function testGetFormObjectDefaultFallback() { ], ]); - $form_object = $this->manager->getFormObject($plugin->reveal(), 'missing', 'fallback'); + $form_object = $this->manager->createInstance($plugin->reveal(), 'missing', 'fallback'); $this->assertSame($plugin->reveal(), $form_object); } /** - * @covers ::getFormObject + * @covers ::createInstance */ - public function testGetFormObjectOperationAware() { - $plugin_form = $this->prophesize(PluginFormInterface::class)->willImplement(OperationAwareFormInterface::class); - $plugin_form->setOperation('operation_aware')->shouldBeCalled(); - - $expected = $plugin_form->reveal(); - - $this->classResolver->getInstanceFromDefinition(get_class($expected))->willReturn($expected); - - $plugin = $this->prophesize(PluginInspectionInterface::class); - $plugin->getPluginDefinition()->willReturn([ - 'form' => [ - 'operation_aware' => get_class($expected), - ], - ]); - - $form_object = $this->manager->getFormObject($plugin->reveal(), 'operation_aware'); - $this->assertSame($expected, $form_object); - } - - /** - * @covers ::getFormObject - */ - public function testGetFormObjectPluginAware() { + public function testCreateInstancePluginAware() { $plugin_form = $this->prophesize(PluginFormInterface::class)->willImplement(PluginAwareInterface::class); $expected = $plugin_form->reveal(); @@ -137,37 +114,28 @@ public function testGetFormObjectPluginAware() { $plugin_form->setPlugin($plugin->reveal())->shouldBeCalled(); - $form_object = $this->manager->getFormObject($plugin->reveal(), 'operation_aware'); + $form_object = $this->manager->createInstance($plugin->reveal(), 'operation_aware'); $this->assertSame($expected, $form_object); } /** - * @covers ::getFormObject - */ - public function testGetFormObjectInvalidPlugin() { - $this->setExpectedException(\InvalidArgumentException::class, 'The plugin must implement "Drupal\Component\Plugin\PluginInspectionInterface"'); - - $this->manager->getFormObject(new \stdClass(), 'anything'); - } - - /** - * @covers ::getFormObject + * @covers ::createInstance */ - public function testGetFormObjectDefinitionException() { + public function testCreateInstanceDefinitionException() { $this->setExpectedException(InvalidPluginDefinitionException::class, 'The "the_plugin_id" plugin did not specify a "anything" form class'); $plugin = $this->prophesize(PluginInspectionInterface::class); $plugin->getPluginId()->willReturn('the_plugin_id'); $plugin->getPluginDefinition()->willReturn([]); - $form_object = $this->manager->getFormObject($plugin->reveal(), 'anything'); + $form_object = $this->manager->createInstance($plugin->reveal(), 'anything'); $this->assertSame(NULL, $form_object); } /** - * @covers ::getFormObject + * @covers ::createInstance */ - public function testGetFormObjectInvalidException() { + public function testCreateInstanceInvalidException() { $this->setExpectedException(InvalidPluginDefinitionException::class, 'The "the_plugin_id" plugin did not specify a valid "invalid" form class, must implement \Drupal\Core\Plugin\PluginFormInterface'); $expected = new \stdClass(); @@ -181,7 +149,7 @@ public function testGetFormObjectInvalidException() { ], ]); - $form_object = $this->manager->getFormObject($plugin->reveal(), 'invalid'); + $form_object = $this->manager->createInstance($plugin->reveal(), 'invalid'); $this->assertSame(NULL, $form_object); }