core/lib/Drupal/Core/Block/BlockBase.php | 2 +- .../Drupal/Tests/Core/Block/BlockBaseTest.php | 35 ++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/core/lib/Drupal/Core/Block/BlockBase.php b/core/lib/Drupal/Core/Block/BlockBase.php index e21926a..8ca3e7c 100644 --- a/core/lib/Drupal/Core/Block/BlockBase.php +++ b/core/lib/Drupal/Core/Block/BlockBase.php @@ -280,7 +280,7 @@ public function getFormClass($operation) { if (isset($this->getPluginDefinition()['forms'][$operation])) { return $this->getPluginDefinition()['forms'][$operation]; } - elseif ($operation === 'configure' && $this instanceof PluginFormInterface) { + elseif ($operation === 'configure') { return static::class; } } diff --git a/core/tests/Drupal/Tests/Core/Block/BlockBaseTest.php b/core/tests/Drupal/Tests/Core/Block/BlockBaseTest.php index 541c0c1..0e53b8f 100644 --- a/core/tests/Drupal/Tests/Core/Block/BlockBaseTest.php +++ b/core/tests/Drupal/Tests/Core/Block/BlockBaseTest.php @@ -3,6 +3,7 @@ namespace Drupal\Tests\Core\Block; use Drupal\block_test\Plugin\Block\TestBlockInstantiation; +use Drupal\Core\Block\BlockBase; use Drupal\Tests\UnitTestCase; /** @@ -42,4 +43,38 @@ public function testGetMachineNameSuggestion() { $this->assertEquals('uberawesome', $block_base->getMachineNameSuggestion()); } + /** + * @covers ::getFormClass + * @covers ::hasFormClass + * @dataProvider providerGetFormClass + */ + public function testGetFormClass(BlockBase $block_plugin, $operation, $expected_class) { + $this->assertSame($expected_class, $block_plugin->getFormClass($operation)); + $this->assertSame($expected_class !== NULL, $block_plugin->hasFormClass($operation)); + } + + /** + * @return array + */ + public function providerGetFormClass() { + $block_plugin_without_forms = new TestBlockInstantiation([], 'block_plugin_without_forms', [ + 'provider' => 'block_test', + ]); + // A block plugin that has a form defined for the 'poke' operation. + $block_plugin_with_forms = new TestBlockInstantiation([], 'block_plugin_with_forms', [ + 'provider' => 'block_test', + 'forms' => [ + 'poke' => static::class, + ], + ]); + return [ + 'block plugin without forms, "configure" operation' => [$block_plugin_without_forms, 'configure', TestBlockInstantiation::class], + 'block plugin without forms, "tickle" operation' => [$block_plugin_without_forms, 'tickle', NULL], + 'block plugin withut forms, "poke" operation' => [$block_plugin_without_forms, 'poke', NULL], + 'block plugin with forms, "configure" operation' => [$block_plugin_with_forms, 'configure', TestBlockInstantiation::class], + 'block plugin with forms, "tickle" operation' => [$block_plugin_with_forms, 'tickle', NULL], + 'block plugin with forms, "poke" operation' => [$block_plugin_with_forms, 'poke', static::class], + ]; + } + }