core/modules/outside_in/outside_in.module | 8 +++++++- .../src/Access/BlockPluginHasOffCanvasFormAccessCheck.php | 7 ++++++- .../Unit/Access/BlockPluginHasOffCanvasFormAccessCheckTest.php | 4 ++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/core/modules/outside_in/outside_in.module b/core/modules/outside_in/outside_in.module index 92bcd94..dec2abb 100644 --- a/core/modules/outside_in/outside_in.module +++ b/core/modules/outside_in/outside_in.module @@ -109,7 +109,13 @@ function outside_in_preprocess_block(&$variables) { // guarantee a smooth experience. // This is an implementation detail that may change in the future. // @see \Drupal\outside_in\Access\BlockPluginHasOffCanvasFormAccessCheck - if (\Drupal::service('plugin.manager.block')->createInstance($variables['plugin_id'])->hasFormClass('off_canvas')) { + /** @var \Drupal\outside_in\Access\BlockPluginHasOffCanvasFormAccessCheck $access_checker */ + $access_checker = \Drupal::service('access_check.outside_in.block.off_canvas_form'); + /** @var \Drupal\Core\Block\BlockManagerInterface $block_plugin_manager */ + $block_plugin_manager = \Drupal::service('plugin.manager.block'); + /** @var \Drupal\Core\Block\BlockPluginInterface $block_plugin */ + $block_plugin = $block_plugin_manager->createInstance($variables['plugin_id']); + if ($access_checker->accessBlockPlugin($block_plugin)) { // Add class and attributes to all blocks to allow Javascript to target. $variables['attributes']['class'][] = 'outside-in-editable'; $variables['attributes']['data-drupal-outsidein'] = 'editable'; diff --git a/core/modules/outside_in/src/Access/BlockPluginHasOffCanvasFormAccessCheck.php b/core/modules/outside_in/src/Access/BlockPluginHasOffCanvasFormAccessCheck.php index 83ebdef..6966943 100644 --- a/core/modules/outside_in/src/Access/BlockPluginHasOffCanvasFormAccessCheck.php +++ b/core/modules/outside_in/src/Access/BlockPluginHasOffCanvasFormAccessCheck.php @@ -9,6 +9,8 @@ /** * Determines whether the requested block has an 'off_canvas' form. + * + * @internal */ class BlockPluginHasOffCanvasFormAccessCheck implements AccessInterface { @@ -21,7 +23,7 @@ class BlockPluginHasOffCanvasFormAccessCheck implements AccessInterface { * @return \Drupal\Core\Access\AccessResultInterface * The access result. */ - public function accessBlock(BlockInterface $block) { + public function access(BlockInterface $block) { /** @var \Drupal\Core\Block\BlockPluginInterface $block_plugin */ $block_plugin = $block->getPlugin(); return $this->accessBlockPlugin($block_plugin); @@ -35,6 +37,9 @@ public function accessBlock(BlockInterface $block) { * * @return \Drupal\Core\Access\AccessResultInterface * The access result. + * + * @see outside_in_preprocess_block() + * @todo Remove when outside_in_preprocess_block() is removed. */ public function accessBlockPlugin(BlockPluginInterface $block_plugin) { return AccessResult::allowedIf($block_plugin->hasFormClass('off_canvas')); 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 104e45d..6d5366b 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,7 @@ class BlockPluginHasOffCanvasFormAccessCheckTest extends UnitTestCase { /** - * @covers ::accessBlock + * @covers ::access * @covers ::accessBlockPlugin * @dataProvider providerTestAccess */ @@ -27,7 +27,7 @@ public function testAccess(array $plugin_definition, AccessResultInterface $expe $block->getPlugin()->willReturn($block_plugin); $access_check = new BlockPluginHasOffCanvasFormAccessCheck(); - $this->assertEquals($expected_access_result, $access_check->accessBlock($block->reveal())); + $this->assertEquals($expected_access_result, $access_check->access($block->reveal())); $this->assertEquals($expected_access_result, $access_check->accessBlockPlugin($block_plugin)); }