Commit cdfcaea1 authored by xjm's avatar xjm

Issue #2904134 by Wim Leers, tedbow: Settings Tray uses the off-canvas dialog...

Issue #2904134 by Wim Leers, tedbow: Settings Tray uses the off-canvas dialog type, but "off_canvas" is not an accurate form plugin name, "settings_tray" is
parent 6eaa470d
......@@ -27,7 +27,7 @@
* in its plugin annotation:
* @code
* forms = {
* "off_canvas" = "\Drupal\some_module\Form\MyBlockOffCanvasForm",
* "settings_tray" = "\Drupal\some_module\Form\MyBlockOffCanvasForm",
* },
* @encode
*
......@@ -36,7 +36,7 @@
* off-canvas form:
* @code
* forms = {
* "off_canvas" = FALSE,
* "settings_tray" = FALSE,
* },
* @encode
*
......@@ -47,7 +47,7 @@
* this added to its annotation:
* @code
* forms = {
* "off_canvas" = "\Drupal\system\Plugin\Block\SystemPoweredByBlock",
* "settings_tray" = "\Drupal\system\Plugin\Block\SystemPoweredByBlock",
* },
* @encode
*
......
......@@ -94,15 +94,15 @@ function outside_in_entity_type_build(array &$entity_types) {
* Implements hook_preprocess_HOOK() for block templates.
*/
function outside_in_preprocess_block(&$variables) {
// Only blocks that have an off_canvas form will have a "Quick Edit" link. We
// could wait for the contextual links to be initialized on the client side,
// and then add the class and data- attribute below there (via JavaScript).
// But that would mean that it would be impossible to show Settings Tray's
// clickable regions immediately when the page loads. When latency is high,
// this will cause flicker.
// @see \Drupal\outside_in\Access\BlockPluginHasOffCanvasFormAccessCheck
/** @var \Drupal\outside_in\Access\BlockPluginHasOffCanvasFormAccessCheck $access_checker */
$access_checker = \Drupal::service('access_check.outside_in.block.off_canvas_form');
// Only blocks that have an settings_tray form will have a "Quick Edit" link.
// We could wait for the contextual links to be initialized on the client
// side, and then add the class and data- attribute below there (via
// JavaScript). But that would mean that it would be impossible to show
// Settings Tray's clickable regions immediately when the page loads. When
// latency is high, this will cause flicker.
// @see \Drupal\outside_in\Access\BlockPluginHasSettingsTrayFormAccessCheck
/** @var \Drupal\outside_in\Access\BlockPluginHasSettingsTrayFormAccessCheck $access_checker */
$access_checker = \Drupal::service('access_check.outside_in.block.settings_tray_form');
/** @var \Drupal\Core\Block\BlockManagerInterface $block_plugin_manager */
$block_plugin_manager = \Drupal::service('plugin.manager.block');
/** @var \Drupal\Core\Block\BlockPluginInterface $block_plugin */
......@@ -147,15 +147,15 @@ function outside_in_toolbar_alter(&$items) {
/**
* Implements hook_block_alter().
*
* Ensures every block plugin definition has an 'off_canvas' form specified.
* Ensures every block plugin definition has an 'settings_tray' form specified.
*
* @see \Drupal\outside_in\Access\BlockPluginHasOffCanvasFormAccessCheck
* @see \Drupal\outside_in\Access\BlockPluginHasSettingsTrayFormAccessCheck
*/
function outside_in_block_alter(&$definitions) {
foreach ($definitions as &$definition) {
// If a block plugin already defines its own off_canvas form, use that form
// instead of specifying one here.
if (isset($definition['forms']['off_canvas'])) {
// If a block plugin already defines its own 'settings_tray' form, use that
// form instead of specifying one here.
if (isset($definition['forms']['settings_tray'])) {
continue;
}
......@@ -165,11 +165,11 @@ function outside_in_block_alter(&$definitions) {
// @todo Move these into the corresponding block plugin annotations in
// https://www.drupal.org/node/2896356.
case 'system_menu_block':
$definition['forms']['off_canvas'] = SystemMenuOffCanvasForm::class;
$definition['forms']['settings_tray'] = SystemMenuOffCanvasForm::class;
break;
case 'system_branding_block':
$definition['forms']['off_canvas'] = SystemBrandingOffCanvasForm::class;
$definition['forms']['settings_tray'] = SystemBrandingOffCanvasForm::class;
break;
// No off-canvas form for the page title block, despite it having
......@@ -178,21 +178,21 @@ function outside_in_block_alter(&$definitions) {
// @todo Move these into the corresponding block plugin annotations in
// https://www.drupal.org/node/2896356.
case 'page_title_block':
$definition['forms']['off_canvas'] = FALSE;
$definition['forms']['settings_tray'] = FALSE;
break;
case 'system_main_block':
$definition['forms']['off_canvas'] = FALSE;
$definition['forms']['settings_tray'] = FALSE;
break;
case 'help_block':
$definition['forms']['off_canvas'] = FALSE;
$definition['forms']['settings_tray'] = FALSE;
break;
// Otherwise, use the block plugin's normal form rather than
// a custom form for Settings Tray.
default:
$definition['forms']['off_canvas'] = $definition['class'];
$definition['forms']['settings_tray'] = $definition['class'];
break;
}
}
......
......@@ -5,4 +5,4 @@ entity.block.off_canvas_form:
_title_callback: '\Drupal\outside_in\Block\BlockEntityOffCanvasForm::title'
requirements:
_permission: 'administer blocks'
_access_block_plugin_has_offcanvas_form: 'TRUE'
_access_block_plugin_has_settings_tray_form: 'TRUE'
......@@ -5,7 +5,7 @@ services:
tags:
- { name: render.main_content_renderer, format: drupal_dialog.off_canvas }
access_check.outside_in.block.off_canvas_form:
class: Drupal\outside_in\Access\BlockPluginHasOffCanvasFormAccessCheck
access_check.outside_in.block.settings_tray_form:
class: Drupal\outside_in\Access\BlockPluginHasSettingsTrayFormAccessCheck
tags:
- { name: access_check, applies_to: _access_block_plugin_has_offcanvas_form }
- { name: access_check, applies_to: _access_block_plugin_has_settings_tray_form }
......@@ -9,17 +9,17 @@
use Drupal\Core\Routing\Access\AccessInterface;
/**
* Determines whether the requested block has an 'off_canvas' form.
* Determines whether the requested block has a 'settings_tray' form.
*
* @internal
*/
class BlockPluginHasOffCanvasFormAccessCheck implements AccessInterface {
class BlockPluginHasSettingsTrayFormAccessCheck implements AccessInterface {
/**
* Checks access for accessing a block's 'off_canvas' form.
* Checks access for accessing a block's 'settings_tray' form.
*
* @param \Drupal\block\BlockInterface $block
* The block whose 'off_canvas' form is being accessed.
* The block whose 'settings_tray' form is being accessed.
*
* @return \Drupal\Core\Access\AccessResultInterface
* The access result.
......@@ -31,10 +31,10 @@ public function access(BlockInterface $block) {
}
/**
* Checks access for accessing a block plugin's 'off_canvas' form.
* Checks access for accessing a block plugin's 'settings_tray' form.
*
* @param \Drupal\Core\Block\BlockPluginInterface $block_plugin
* The block plugin whose 'off_canvas' form is being accessed.
* The block plugin whose 'settings_tray' form is being accessed.
*
* @return \Drupal\Core\Access\AccessResultInterface
* The access result.
......@@ -42,7 +42,7 @@ public function access(BlockInterface $block) {
* @see outside_in_preprocess_block()
*/
public function accessBlockPlugin(BlockPluginInterface $block_plugin) {
return AccessResult::allowedIf($block_plugin instanceof PluginWithFormsInterface && $block_plugin->hasFormClass('off_canvas'));
return AccessResult::allowedIf($block_plugin instanceof PluginWithFormsInterface && $block_plugin->hasFormClass('settings_tray'));
}
}
......@@ -111,7 +111,7 @@ protected function submitVisibility(array $form, FormStateInterface $form_state)
*/
protected function getPluginForm(BlockPluginInterface $block) {
if ($block instanceof PluginWithFormsInterface) {
return $this->pluginFormFactory->createInstance($block, 'off_canvas', 'configure');
return $this->pluginFormFactory->createInstance($block, 'settings_tray', 'configure');
}
return $block;
}
......
......@@ -6,9 +6,9 @@
use Drupal\Core\Plugin\PluginFormBase;
/**
* @see \Drupal\outside_in_test\Plugin\Block\OffCanvasFormAnnotationIsClassBlock
* @see \Drupal\outside_in_test\Plugin\Block\SettingsTrayFormAnnotationIsClassBlock
*/
class OffCanvasFormAnnotationIsClassBlockForm extends PluginFormBase {
class SettingsTrayFormAnnotationIsClassBlockForm extends PluginFormBase {
/**
* The block plugin.
......
......@@ -5,17 +5,17 @@
use Drupal\Core\Block\BlockBase;
/**
* Block that explicitly provides an "off_canvas" form class.
* Block that explicitly provides a "settings_tray" form class.
*
* @Block(
* id = "outside_in_test_class",
* admin_label = "Settings Tray test block: forms[off_canvas]=class",
* admin_label = "Settings Tray test block: forms[settings_tray]=class",
* forms = {
* "off_canvas" = "\Drupal\outside_in_test\Form\OffCanvasFormAnnotationIsClassBlockForm",
* "settings_tray" = "\Drupal\outside_in_test\Form\SettingsTrayFormAnnotationIsClassBlockForm",
* },
* )
*/
class OffCanvasFormAnnotationIsClassBlock extends BlockBase {
class SettingsTrayFormAnnotationIsClassBlock extends BlockBase {
/**
* {@inheritdoc}
......
......@@ -5,17 +5,17 @@
use Drupal\Core\Block\BlockBase;
/**
* Block that explicitly provides no "off_canvas" form, thus opting out.
* Block that explicitly provides no "settings_tray" form, thus opting out.
*
* @Block(
* id = "outside_in_test_false",
* admin_label = "Settings Tray test block: forms[off_canvas]=FALSE",
* admin_label = "Settings Tray test block: forms[settings_tray]=FALSE",
* forms = {
* "off_canvas" = FALSE,
* "settings_tray" = FALSE,
* },
* )
*/
class OffCanvasFormAnnotationIsFalseBlock extends BlockBase {
class SettingsTrayFormAnnotationIsFalseBlock extends BlockBase {
/**
* {@inheritdoc}
......
......@@ -9,10 +9,10 @@
*
* @Block(
* id = "outside_in_test_none",
* admin_label = "Settings Tray test block: forms[off_canvas] is not specified",
* admin_label = "Settings Tray test block: forms[settings_tray] is not specified",
* )
*/
class OffCanvasFormAnnotationNoneBlock extends BlockBase {
class SettingsTrayFormAnnotationNoneBlock extends BlockBase {
/**
* {@inheritdoc}
......
......@@ -34,7 +34,7 @@ protected function getBlockSelector(Block $block) {
}
/**
* Tests the three possible forms[off_canvas] annotations: class, FALSE, none.
* Tests the 3 possible forms[settings_tray] annotations: class, FALSE, none.
*
* There is also functional JS test coverage to ensure that the two blocks
* that support Settings Tray (the "class" and "none" cases) do work
......@@ -44,9 +44,9 @@ protected function getBlockSelector(Block $block) {
*/
public function testPossibleAnnotations() {
$test_block_plugin_ids = [
// Block that explicitly provides an "off_canvas" form class.
// Block that explicitly provides an "settings_tray" form class.
'outside_in_test_class',
// Block that explicitly provides no "off_canvas" form, thus opting out.
// Block that explicitly provides no "settings_tray" form, thus opting out.
'outside_in_test_false',
// Block that does nothing explicit for Settings Tray.
'outside_in_test_none',
......@@ -95,7 +95,7 @@ public function testOptOut() {
// Assert that block has been marked as "editable" and contextual that
// should exist does.
$web_assert->elementExists('css', $this->getBlockSelector($non_excluded_block) . "[data-drupal-outsidein=\"editable\"]");
// Assert that each block that has a "forms[off_canvas] = FALSE" annotation:
// Assert that each block that has a "forms[settings_tray] = FALSE" annotation:
// - is still rendered on the page
// - but is not marked as "editable" by outside_in_preprocess_block()
// - and does not have the Settings Tray contextual link.
......
......@@ -5,8 +5,8 @@
use Drupal\block\Entity\Block;
use Drupal\block_content\Entity\BlockContent;
use Drupal\block_content\Entity\BlockContentType;
use Drupal\outside_in_test\Plugin\Block\OffCanvasFormAnnotationIsClassBlock;
use Drupal\outside_in_test\Plugin\Block\OffCanvasFormAnnotationNoneBlock;
use Drupal\outside_in_test\Plugin\Block\SettingsTrayFormAnnotationIsClassBlock;
use Drupal\outside_in_test\Plugin\Block\SettingsTrayFormAnnotationNoneBlock;
use Drupal\user\Entity\Role;
/**
......@@ -185,7 +185,7 @@ public function providerTestBlocks() {
],
// This is the functional JS test coverage accompanying
// \Drupal\Tests\outside_in\Functional\OutsideInTest::testPossibleAnnotations().
OffCanvasFormAnnotationIsClassBlock::class => [
SettingsTrayFormAnnotationIsClassBlock::class => [
'block_plugin' => 'outside_in_test_class',
'new_page_text' => NULL,
'element_selector' => 'span',
......@@ -195,7 +195,7 @@ public function providerTestBlocks() {
],
// This is the functional JS test coverage accompanying
// \Drupal\Tests\outside_in\Functional\OutsideInTest::testPossibleAnnotations().
OffCanvasFormAnnotationNoneBlock::class => [
SettingsTrayFormAnnotationNoneBlock::class => [
'block_plugin' => 'outside_in_test_none',
'new_page_text' => NULL,
'element_selector' => 'span',
......
......@@ -8,15 +8,15 @@
use Drupal\Core\Access\AccessResultNeutral;
use Drupal\Core\Block\BlockPluginInterface;
use Drupal\Core\Plugin\PluginWithFormsInterface;
use Drupal\outside_in\Access\BlockPluginHasOffCanvasFormAccessCheck;
use Drupal\outside_in\Access\BlockPluginHasSettingsTrayFormAccessCheck;
use Drupal\Tests\UnitTestCase;
use Prophecy\Argument;
/**
* @coversDefaultClass \Drupal\outside_in\Access\BlockPluginHasOffCanvasFormAccessCheck
* @coversDefaultClass \Drupal\outside_in\Access\BlockPluginHasSettingsTrayFormAccessCheck
* @group outside_in
*/
class BlockPluginHasOffCanvasFormAccessCheckTest extends UnitTestCase {
class BlockPluginHasSettingsTrayFormAccessCheckTest extends UnitTestCase {
/**
* @covers ::access
......@@ -36,7 +36,7 @@ public function testAccess($with_forms, array $plugin_definition, AccessResultIn
$block = $this->prophesize(BlockInterface::class);
$block->getPlugin()->willReturn($block_plugin->reveal());
$access_check = new BlockPluginHasOffCanvasFormAccessCheck();
$access_check = new BlockPluginHasSettingsTrayFormAccessCheck();
$this->assertEquals($expected_access_result, $access_check->access($block->reveal()));
$this->assertEquals($expected_access_result, $access_check->accessBlockPlugin($block_plugin->reveal()));
}
......@@ -45,49 +45,49 @@ public function testAccess($with_forms, array $plugin_definition, AccessResultIn
* Provides test data for ::testAccess().
*/
public function providerTestAccess() {
$annotation_forms_off_canvas_class = [
$annotation_forms_settings_tray_class = [
'forms' => [
'off_canvas' => $this->randomMachineName(),
'settings_tray' => $this->randomMachineName(),
],
];
$annotation_forms_off_canvas_not_set = [];
$annotation_forms_off_canvas_false = [
$annotation_forms_settings_tray_not_set = [];
$annotation_forms_settings_tray_false = [
'forms' => [
'off_canvas' => FALSE,
'settings_tray' => FALSE,
],
];
return [
'block plugin with forms, forms[off_canvas] set to class' => [
'block plugin with forms, forms[settings_tray] set to class' => [
TRUE,
$annotation_forms_off_canvas_class,
$annotation_forms_settings_tray_class,
new AccessResultAllowed(),
],
'block plugin with forms, forms[off_canvas] not set' => [
'block plugin with forms, forms[settings_tray] not set' => [
TRUE,
$annotation_forms_off_canvas_not_set,
$annotation_forms_settings_tray_not_set,
new AccessResultNeutral(),
],
'block plugin with forms, forms[off_canvas] set to FALSE' => [
'block plugin with forms, forms[settings_tray] set to FALSE' => [
TRUE,
$annotation_forms_off_canvas_false,
$annotation_forms_settings_tray_false,
new AccessResultNeutral(),
],
// In practice, all block plugins extend BlockBase, which means they all
// implement PluginWithFormsInterface, but this may change in the future.
// This ensures Settings Tray will continue to work correctly.
'block plugin without forms, forms[off_canvas] set to class' => [
'block plugin without forms, forms[settings_tray] set to class' => [
FALSE,
$annotation_forms_off_canvas_class,
$annotation_forms_settings_tray_class,
new AccessResultNeutral(),
],
'block plugin without forms, forms[off_canvas] not set' => [
'block plugin without forms, forms[settings_tray] not set' => [
FALSE,
$annotation_forms_off_canvas_not_set,
$annotation_forms_settings_tray_not_set,
new AccessResultNeutral(),
],
'block plugin without forms, forms[off_canvas] set to FALSE' => [
'block plugin without forms, forms[settings_tray] set to FALSE' => [
FALSE,
$annotation_forms_off_canvas_false,
$annotation_forms_settings_tray_false,
new AccessResultNeutral(),
],
];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment