Unverified Commit 0c3ea725 authored by alexpott's avatar alexpott

Issue #2973615 by johndevman, tim.plunkett, johnzzon: Add Section delta as...

Issue #2973615 by johndevman, tim.plunkett, johnzzon: Add Section delta as extra data on filtered block definitions
parent 2ea71c67
......@@ -63,8 +63,13 @@ public function build(SectionStorageInterface $section_storage, $delta, $region)
$build['#type'] = 'container';
$build['#attributes']['class'][] = 'block-categories';
// @todo Explicitly cast delta to an integer, remove this in
// https://www.drupal.org/project/drupal/issues/2984509.
$delta = (int) $delta;
$definitions = $this->blockManager->getFilteredDefinitions('layout_builder', $this->getAvailableContexts($section_storage), [
'section_storage' => $section_storage,
'delta' => $delta,
'region' => $region,
]);
foreach ($this->blockManager->getGroupedDefinitions($definitions) as $category => $blocks) {
......
......@@ -8,7 +8,7 @@
/**
* Implements hook_plugin_filter_TYPE__CONSUMER_alter().
*/
function layout_builder_test_plugin_filter_block__layout_builder_alter(array &$definitions) {
function layout_builder_test_plugin_filter_block__layout_builder_alter(array &$definitions, array $extra) {
// Explicitly remove the "Help" blocks from the list.
unset($definitions['help_block']);
......@@ -17,6 +17,11 @@ function layout_builder_test_plugin_filter_block__layout_builder_alter(array &$d
'sticky',
];
// Remove "Changed" field if this is the first section.
if ($extra['delta'] === 0) {
$disallowed_fields[] = 'changed';
}
foreach ($definitions as $plugin_id => $definition) {
// Field block IDs are in the form 'field_block:{entity}:{bundle}:{name}',
// for example 'field_block:node:article:revision_timestamp'.
......
......@@ -351,6 +351,24 @@ public function testLayoutBuilderChooseBlocksAlter() {
// Verify that blocks explicitly removed are not present.
$assert_session->linkNotExists('Help');
$assert_session->linkNotExists('Sticky at top of lists');
// Verify that Changed block is not present on first section.
$assert_session->linkNotExists('Changed');
// Go back to Manage layout.
$this->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default');
$this->clickLink('Manage layout');
// Add a new section.
$this->clickLink('Add Section', 1);
$assert_session->linkExists('Two column');
$this->clickLink('Two column');
// Add a new block to second section.
$this->clickLink('Add Block', 1);
// Verify that Changed block is present on second section.
$assert_session->linkExists('Changed');
}
/**
......
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