Verified Commit 8418cba1 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #3392572 by benjifisher, Liam Morland, ricovandevin, Anybody,...

Issue #3392572 by benjifisher, Liam Morland, ricovandevin, Anybody, smustgrave, quietone, sabrina.liman, carolpettirossi, longwave, alexpott: Add missing category to Drupal\layout_builder\Plugin\Layout\BlankLayout and let modules and themes alter the list of layouts

(cherry picked from commit cc32980f)
parent de70a642
Loading
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -227,7 +227,8 @@ public function getGroupedDefinitions(?array $definitions = NULL, $label_key = '
   */
  public function getLayoutOptions() {
    $layout_options = [];
    foreach ($this->getGroupedDefinitions() as $category => $layout_definitions) {
    $filtered_definitions = $this->getFilteredDefinitions($this->getType());
    foreach ($this->getGroupedDefinitions($filtered_definitions) as $category => $layout_definitions) {
      foreach ($layout_definitions as $name => $layout_definition) {
        $layout_options[$category][$name] = $layout_definition->getLabel();
      }
+2 −1
Original line number Diff line number Diff line
@@ -18,7 +18,8 @@
 */
#[Layout(
  id: 'layout_builder_blank',
  label: new TranslatableMarkup('Blank'),
  label: new TranslatableMarkup('Blank Layout'),
  category: new TranslatableMarkup('Blank Layout'),
)]
class BlankLayout extends LayoutDefault {

+32 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
use Drupal\Core\Layout\LayoutInterface;
use Drupal\Core\Layout\LayoutPluginManager;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\Theme\ThemeManagerInterface;
use Drupal\Tests\UnitTestCase;
use org\bovigo\vfs\vfsStream;
use Prophecy\Argument;
@@ -43,6 +44,13 @@ class LayoutPluginManagerTest extends UnitTestCase {
   */
  protected $themeHandler;

  /**
   * The theme manager.
   *
   * @var \Drupal\Core\Theme\ThemeManagerInterface
   */
  protected $themeManager;

  /**
   * Cache backend instance.
   *
@@ -67,6 +75,8 @@ protected function setUp(): void {

    $container = new ContainerBuilder();
    $container->set('string_translation', $this->getStringTranslationStub());
    $this->themeManager = $this->prophesize(ThemeManagerInterface::class);
    $container->set('theme.manager', $this->themeManager->reveal());
    \Drupal::setContainer($container);

    $this->moduleHandler = $this->prophesize(ModuleHandlerInterface::class);
@@ -347,6 +357,28 @@ public function testGetGroupedDefinitions(): void {
    }
  }

  /**
   * @covers ::getLayoutOptions
   *
   * Test that modules and themes can alter the list of layouts.
   */
  public function testGetLayoutOptions(): void {
    $this->moduleHandler->alter(
      ['plugin_filter_layout', 'plugin_filter_layout__layout'],
      Argument::type('array'),
      [],
      'layout',
    )->shouldBeCalled();
    $this->themeManager->alter(
      ['plugin_filter_layout', 'plugin_filter_layout__layout'],
      Argument::type('array'),
      [],
      'layout',
    )->shouldBeCalled();

    $this->layoutPluginManager->getLayoutOptions();
  }

  /**
   * Sets up the filesystem with YAML files and annotated plugins.
   */