Commit 87646bb8 authored by catch's avatar catch

Issue #2968139 by tim.plunkett, tedbow: Layout Builder field blocks show up on...

Issue #2968139 by tim.plunkett, tedbow: Layout Builder field blocks show up on Block UI when they shouldn't
parent 576bc7fe
......@@ -203,3 +203,21 @@ function layout_builder_block_content_access(EntityInterface $entity, $operation
}
return AccessResult::forbidden();
}
/**
* Implements hook_plugin_filter_TYPE__CONSUMER_alter().
*/
function layout_builder_plugin_filter_block__block_ui_alter(array &$definitions, array $extra) {
foreach ($definitions as $id => $definition) {
// Filter out any layout_builder definition with required contexts.
if ($definition['provider'] === 'layout_builder' && !empty($definition['context'])) {
/** @var \Drupal\Core\Plugin\Context\ContextDefinitionInterface $context */
foreach ($definition['context'] as $context) {
if ($context->isRequired()) {
unset($definitions[$id]);
break;
}
}
}
}
}
# See \Drupal\layout_builder_fieldblock_test\Plugin\Block\FieldBlock.
block.settings.field_block_test:*:*:*:
type: block.settings.field_block:*:*:*
name: 'Layout Builder test'
type: module
description: 'Support module for testing layout building.'
package: Testing
version: VERSION
core: 8.x
<?php
namespace Drupal\layout_builder_fieldblock_test\Plugin\Block;
use Drupal\layout_builder\Plugin\Block\FieldBlock as LayoutBuilderFieldBlock;
/**
* Provides test field block to test with Block UI.
*
* \Drupal\Tests\layout_builder\FunctionalJavascript\FieldBlockTest provides
* test coverage of complex AJAX interactions within certain field blocks.
* layout_builder_plugin_filter_block__block_ui_alter() removes certain blocks
* with 'layout_builder' as the provider. To make these blocks available during
* testing, this plugin uses the same deriver but each derivative will have a
* different provider.
*
* @Block(
* id = "field_block_test",
* deriver = "\Drupal\layout_builder\Plugin\Derivative\FieldBlockDeriver",
* )
*
* @see \Drupal\Tests\layout_builder\FunctionalJavascript\FieldBlockTest
* @see layout_builder_plugin_filter_block__block_ui_alter()
*/
class FieldBlock extends LayoutBuilderFieldBlock {
}
......@@ -557,4 +557,26 @@ public function testBlockPlaceholder() {
$assert_session->pageTextContains($block_content);
}
/**
* Tests the Block UI when Layout Builder is installed.
*/
public function testBlockUiListing() {
$assert_session = $this->assertSession();
$page = $this->getSession()->getPage();
$this->drupalLogin($this->drupalCreateUser([
'administer blocks',
]));
$this->drupalGet('admin/structure/block');
$page->clickLink('Place block');
// Ensure that blocks expected to appear are available.
$assert_session->pageTextContains('Test HTML block');
$assert_session->pageTextContains('Block test');
// Ensure that blocks not expected to appear are not available.
$assert_session->pageTextNotContains('Body');
$assert_session->pageTextNotContains('Content fields');
}
}
......@@ -16,7 +16,14 @@ class FieldBlockTest extends WebDriverTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['block', 'datetime', 'layout_builder', 'user'];
protected static $modules = [
'block',
'datetime',
'layout_builder',
'user',
// See \Drupal\layout_builder_fieldblock_test\Plugin\Block\FieldBlock.
'layout_builder_fieldblock_test',
];
/**
* {@inheritdoc}
......@@ -67,7 +74,7 @@ public function testFieldBlock() {
$assert_session->pageTextNotContains('Initial email');
$assert_session->pageTextContains('Date field');
$block_url = 'admin/structure/block/add/field_block%3Auser%3Auser%3Afield_date/classy';
$block_url = 'admin/structure/block/add/field_block_test%3Auser%3Auser%3Afield_date/classy';
$assert_session->linkByHrefExists($block_url);
$this->drupalGet($block_url);
......
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