core/modules/outside_in/outside_in.api.php | 23 +++++++--------------- .../BlockPluginHasOffCanvasFormAccessCheck.php | 16 ++++++++++++++- .../OutsideInBlockFormTest.php | 8 ++++---- .../BlockPluginHasOffCanvasFormAccessCheckTest.php | 6 ++++-- 4 files changed, 30 insertions(+), 23 deletions(-) diff --git a/core/modules/outside_in/outside_in.api.php b/core/modules/outside_in/outside_in.api.php index c3ed73e..913036f 100644 --- a/core/modules/outside_in/outside_in.api.php +++ b/core/modules/outside_in/outside_in.api.php @@ -10,25 +10,16 @@ * @{ * Settings Tray API * - * @section sec_overview Overview and terminology - * - * The goal of the Settings Tray module is to make administering blocks easier, - * and therefore to make the site building experience faster and more pleasant. - * - * It achieves this by building on the infrastructure that the Contextual - * Links module provides: Settings Tray provides a "Quick Edit" contextual link - * for blocks. Clicking this contextual link opens the Settings Tray, which - * allows to change the contents of the block (not the visibility conditions). - * This means blocks can be modified without leaving the page. - * - * The Settings Tray uses a variant of a standard dialog: an off-canvas dialog. - * * @section sec_api The API: the form in the Settings Tray * * By default, every block will show their built-in form in the Settings Tray. - * However, many blocks would benefit from a tailored form which limits the form - * to only the form items that affect the content of the rendered block: this - * results in a better experience. + * However, many blocks would benefit from a tailored form which either: + * - limits the form to only the form items that affect the content of the + * rendered block, or + * - adds additional form items to edit configuration that is rendered by the + * block. + * This results in a better experience: the Settings Tray form always allows the + * user to change what is rendered by the block. * * Each block plugin can specify which form to use in the off-canvas dialog: * @code diff --git a/core/modules/outside_in/src/Access/BlockPluginHasOffCanvasFormAccessCheck.php b/core/modules/outside_in/src/Access/BlockPluginHasOffCanvasFormAccessCheck.php index e8536f7..83ebdef 100644 --- a/core/modules/outside_in/src/Access/BlockPluginHasOffCanvasFormAccessCheck.php +++ b/core/modules/outside_in/src/Access/BlockPluginHasOffCanvasFormAccessCheck.php @@ -4,6 +4,7 @@ use Drupal\block\BlockInterface; use Drupal\Core\Access\AccessResult; +use Drupal\Core\Block\BlockPluginInterface; use Drupal\Core\Routing\Access\AccessInterface; /** @@ -20,9 +21,22 @@ class BlockPluginHasOffCanvasFormAccessCheck implements AccessInterface { * @return \Drupal\Core\Access\AccessResultInterface * The access result. */ - public function access(BlockInterface $block) { + public function accessBlock(BlockInterface $block) { /** @var \Drupal\Core\Block\BlockPluginInterface $block_plugin */ $block_plugin = $block->getPlugin(); + return $this->accessBlockPlugin($block_plugin); + } + + /** + * Checks access for accessing a block plugin's 'off_canvas' form. + * + * @param \Drupal\Core\Block\BlockPluginInterface $block_plugin + * The block plugin whose 'off_canvas' form is being accessed. + * + * @return \Drupal\Core\Access\AccessResultInterface + * The access result. + */ + public function accessBlockPlugin(BlockPluginInterface $block_plugin) { return AccessResult::allowedIf($block_plugin->hasFormClass('off_canvas')); } diff --git a/core/modules/outside_in/tests/src/FunctionalJavascript/OutsideInBlockFormTest.php b/core/modules/outside_in/tests/src/FunctionalJavascript/OutsideInBlockFormTest.php index 4353355..191010d 100644 --- a/core/modules/outside_in/tests/src/FunctionalJavascript/OutsideInBlockFormTest.php +++ b/core/modules/outside_in/tests/src/FunctionalJavascript/OutsideInBlockFormTest.php @@ -186,8 +186,8 @@ public function providerTestBlocks() { 'block_plugin' => 'outside_in_test_class', 'new_page_text' => NULL, 'element_selector' => 'span', - 'label_selector' => 'h2', - 'button_text' => 'Save Settings Tray test block: forms[off_canvas]=class', + 'label_selector' => NULL, + 'button_text' => NULL, 'toolbar_item' => NULL, ], // This is the functional JS test coverage accompanying testPossibleAnnotations(). @@ -195,8 +195,8 @@ public function providerTestBlocks() { 'block_plugin' => 'outside_in_test_none', 'new_page_text' => NULL, 'element_selector' => 'span', - 'label_selector' => 'h2', - 'button_text' => 'Save Settings Tray test block: forms[off_canvas] is not specified', + 'label_selector' => NULL, + 'button_text' => NULL, 'toolbar_item' => NULL, ], ]; diff --git a/core/modules/outside_in/tests/src/Unit/Access/BlockPluginHasOffCanvasFormAccessCheckTest.php b/core/modules/outside_in/tests/src/Unit/Access/BlockPluginHasOffCanvasFormAccessCheckTest.php index 0643688..104e45d 100644 --- a/core/modules/outside_in/tests/src/Unit/Access/BlockPluginHasOffCanvasFormAccessCheckTest.php +++ b/core/modules/outside_in/tests/src/Unit/Access/BlockPluginHasOffCanvasFormAccessCheckTest.php @@ -17,7 +17,8 @@ class BlockPluginHasOffCanvasFormAccessCheckTest extends UnitTestCase { /** - * @covers ::access + * @covers ::accessBlock + * @covers ::accessBlockPlugin * @dataProvider providerTestAccess */ public function testAccess(array $plugin_definition, AccessResultInterface $expected_access_result) { @@ -26,7 +27,8 @@ public function testAccess(array $plugin_definition, AccessResultInterface $expe $block->getPlugin()->willReturn($block_plugin); $access_check = new BlockPluginHasOffCanvasFormAccessCheck(); - $this->assertEquals($expected_access_result, $access_check->access($block->reveal())); + $this->assertEquals($expected_access_result, $access_check->accessBlock($block->reveal())); + $this->assertEquals($expected_access_result, $access_check->accessBlockPlugin($block_plugin)); } public function providerTestAccess() {