diff --git a/core/lib/Drupal/Core/Layout/LayoutPluginManager.php b/core/lib/Drupal/Core/Layout/LayoutPluginManager.php index bc97ec66e05d5564d930d360028d06a2ccc28ad3..5454d01fd8c999bdb70a999bd2f927bd6414038f 100644 --- a/core/lib/Drupal/Core/Layout/LayoutPluginManager.php +++ b/core/lib/Drupal/Core/Layout/LayoutPluginManager.php @@ -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(); } diff --git a/core/modules/layout_builder/src/Plugin/Layout/BlankLayout.php b/core/modules/layout_builder/src/Plugin/Layout/BlankLayout.php index 7d5b83e3c8a6c42d930885e35519ebed15a793ec..9fc5372c5a2ba5626f3c39d8cc0591d04947d68d 100644 --- a/core/modules/layout_builder/src/Plugin/Layout/BlankLayout.php +++ b/core/modules/layout_builder/src/Plugin/Layout/BlankLayout.php @@ -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 { diff --git a/core/tests/Drupal/Tests/Core/Layout/LayoutPluginManagerTest.php b/core/tests/Drupal/Tests/Core/Layout/LayoutPluginManagerTest.php index 62547d63c976029bef1cafe03e31f994cebac903..3388c7a3010ba5e48a303e722d1aee83d07bf67e 100644 --- a/core/tests/Drupal/Tests/Core/Layout/LayoutPluginManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Layout/LayoutPluginManagerTest.php @@ -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. */