Loading layout_builder_styles.install +38 −0 Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay; use Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage; use Drupal\layout_builder_styles\LayoutBuilderStyleInterface; /** * Migrate away from using section component TPS to the old additional property. Loading Loading @@ -93,3 +94,40 @@ function layout_builder_styles_update_8002() { $config->set('form_type', 'checkboxes'); $config->save(); } /** * Allow block styles per block type for any defined reusable block instances. */ function layout_builder_styles_update_8003() { // Per #3068722, block restrictions/allowances will no longer be supported // for individual block instances. Find any defined instance allowances // and re-save that allowance as a block type whitelist. // This will effectively maintain allowances for those block instances, while // theoretically adding allowances for other block instances which had // been restricted. $styles = \Drupal::entityTypeManager() ->getStorage('layout_builder_style') ->loadByProperties([ 'type' => LayoutBuilderStyleInterface::TYPE_COMPONENT, ]); foreach ($styles as $style) { $restrictions = $style->getBlockRestrictions(); foreach ($restrictions as $key => $allowed) { // If this is a reusable block, retrieve the block bundle. if (strpos($allowed, "block_content:") === 0) { $uuid = str_replace('block_content:', '', $allowed); $bundle = \Drupal::service('entity.repository')->loadEntityByUuid('block_content', $uuid) ->bundle(); if ($bundle && !in_array('inline_block:' . $bundle, $restrictions)) { // Add a block type allowance if it doesn't exist. array_push($restrictions, 'inline_block:' . $bundle); } // Remove the now defunct block instance allowance. unset($restrictions[$key]); } } // Re-save style restrictions. $style->set('block_restrictions', $restrictions); $style->save(); } } src/Form/LayoutBuilderStyleForm.php +11 −5 Original line number Diff line number Diff line Loading @@ -99,11 +99,17 @@ class LayoutBuilderStyleForm extends EntityForm implements ContainerInjectionInt $blockDefinitions = $this->blockManager->getDefinitions(); $blockDefinitions = $this->blockManager->getGroupedDefinitions($blockDefinitions); // Remove individual reusable blocks from list. unset($blockDefinitions['Custom']); if (isset($blockDefinitions['Inline blocks'])) { // Relabel the inline block type listing as generic "Custom block types". // This category will apply to inline blocks & reusable blocks. $blockDefinitions['Custom block types'] = $blockDefinitions['Inline blocks']; unset($blockDefinitions['Inline blocks']); ksort($blockDefinitions); } $form['block_restrictions'] = [ '#type' => 'details', Loading tests/src/Functional/LayoutBuilderStyleTest.php +6 −0 Original line number Diff line number Diff line Loading @@ -309,6 +309,12 @@ class LayoutBuilderStyleTest extends BrowserTestBase { 'block_restrictions' => ['inline_block:alternate', 'field_block:node:bundle_with_section_field:promote'], ])->save(); // Block instances are not allowed to be restricted. $this->drupalGet('admin/config/content/layout_builder_style/unrestricted/edit'); foreach ($blocks as $label => $uuid) { $assert_session->elementNotExists('css', 'input[name="block_restrictions[block_content:' . $uuid . ']"]'); } // Set the configuration to allow multiple styles per block. $this->drupalGet('/admin/config/content/layout_builder_style/config'); $page->selectFieldOption('edit-multiselect-multiple', 'multiple'); Loading Loading
layout_builder_styles.install +38 −0 Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay; use Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage; use Drupal\layout_builder_styles\LayoutBuilderStyleInterface; /** * Migrate away from using section component TPS to the old additional property. Loading Loading @@ -93,3 +94,40 @@ function layout_builder_styles_update_8002() { $config->set('form_type', 'checkboxes'); $config->save(); } /** * Allow block styles per block type for any defined reusable block instances. */ function layout_builder_styles_update_8003() { // Per #3068722, block restrictions/allowances will no longer be supported // for individual block instances. Find any defined instance allowances // and re-save that allowance as a block type whitelist. // This will effectively maintain allowances for those block instances, while // theoretically adding allowances for other block instances which had // been restricted. $styles = \Drupal::entityTypeManager() ->getStorage('layout_builder_style') ->loadByProperties([ 'type' => LayoutBuilderStyleInterface::TYPE_COMPONENT, ]); foreach ($styles as $style) { $restrictions = $style->getBlockRestrictions(); foreach ($restrictions as $key => $allowed) { // If this is a reusable block, retrieve the block bundle. if (strpos($allowed, "block_content:") === 0) { $uuid = str_replace('block_content:', '', $allowed); $bundle = \Drupal::service('entity.repository')->loadEntityByUuid('block_content', $uuid) ->bundle(); if ($bundle && !in_array('inline_block:' . $bundle, $restrictions)) { // Add a block type allowance if it doesn't exist. array_push($restrictions, 'inline_block:' . $bundle); } // Remove the now defunct block instance allowance. unset($restrictions[$key]); } } // Re-save style restrictions. $style->set('block_restrictions', $restrictions); $style->save(); } }
src/Form/LayoutBuilderStyleForm.php +11 −5 Original line number Diff line number Diff line Loading @@ -99,11 +99,17 @@ class LayoutBuilderStyleForm extends EntityForm implements ContainerInjectionInt $blockDefinitions = $this->blockManager->getDefinitions(); $blockDefinitions = $this->blockManager->getGroupedDefinitions($blockDefinitions); // Remove individual reusable blocks from list. unset($blockDefinitions['Custom']); if (isset($blockDefinitions['Inline blocks'])) { // Relabel the inline block type listing as generic "Custom block types". // This category will apply to inline blocks & reusable blocks. $blockDefinitions['Custom block types'] = $blockDefinitions['Inline blocks']; unset($blockDefinitions['Inline blocks']); ksort($blockDefinitions); } $form['block_restrictions'] = [ '#type' => 'details', Loading
tests/src/Functional/LayoutBuilderStyleTest.php +6 −0 Original line number Diff line number Diff line Loading @@ -309,6 +309,12 @@ class LayoutBuilderStyleTest extends BrowserTestBase { 'block_restrictions' => ['inline_block:alternate', 'field_block:node:bundle_with_section_field:promote'], ])->save(); // Block instances are not allowed to be restricted. $this->drupalGet('admin/config/content/layout_builder_style/unrestricted/edit'); foreach ($blocks as $label => $uuid) { $assert_session->elementNotExists('css', 'input[name="block_restrictions[block_content:' . $uuid . ']"]'); } // Set the configuration to allow multiple styles per block. $this->drupalGet('/admin/config/content/layout_builder_style/config'); $page->selectFieldOption('edit-multiselect-multiple', 'multiple'); Loading