diff --git a/core/modules/layout_builder/src/Controller/ChooseSectionController.php b/core/modules/layout_builder/src/Controller/ChooseSectionController.php index ec27e92626f36f89177a32b6f34fa2b8ab9de847..29778eb3866fc3652e1201a8faf111f4f4acd9de 100644 --- a/core/modules/layout_builder/src/Controller/ChooseSectionController.php +++ b/core/modules/layout_builder/src/Controller/ChooseSectionController.php @@ -69,8 +69,8 @@ public function build(SectionStorageInterface $section_storage, $delta) { $item = [ '#type' => 'link', '#title' => [ - $definition->getIcon(60, 80, 1, 3), - [ + 'icon' => $definition->getIcon(60, 80, 1, 3), + 'label' => [ '#type' => 'container', '#children' => $definition->getLabel(), ], @@ -90,10 +90,10 @@ public function build(SectionStorageInterface $section_storage, $delta) { $item['#attributes']['data-dialog-type'][] = 'dialog'; $item['#attributes']['data-dialog-renderer'][] = 'off_canvas'; } - $items[] = $item; + $items[$plugin_id] = $item; } $output['layouts'] = [ - '#theme' => 'item_list', + '#theme' => 'item_list__layouts', '#items' => $items, '#attributes' => [ 'class' => [ diff --git a/core/modules/layout_builder/tests/modules/layout_builder_field_block_theme_suggestions_test/layout_builder_field_block_theme_suggestions_test.module b/core/modules/layout_builder/tests/modules/layout_builder_field_block_theme_suggestions_test/layout_builder_field_block_theme_suggestions_test.module deleted file mode 100644 index 729f3a333165a8ec5763481ebd128006c7e1ca71..0000000000000000000000000000000000000000 --- a/core/modules/layout_builder/tests/modules/layout_builder_field_block_theme_suggestions_test/layout_builder_field_block_theme_suggestions_test.module +++ /dev/null @@ -1,19 +0,0 @@ -<?php - -/** - * @file - * For testing Field Block theme suggestions. - */ - -/** - * Implements hook_theme(). - */ -function layout_builder_field_block_theme_suggestions_test_theme() { - // It is necessary to explicitly register the template via hook_theme() - // because it is added via a module, not a theme. - return [ - 'field__node__body__bundle_with_section_field__default' => [ - 'base hook' => 'field', - ], - ]; -} diff --git a/core/modules/layout_builder/tests/modules/layout_builder_field_block_theme_suggestions_test/layout_builder_field_block_theme_suggestions_test.info.yml b/core/modules/layout_builder/tests/modules/layout_builder_theme_suggestions_test/layout_builder_theme_suggestions_test.info.yml similarity index 100% rename from core/modules/layout_builder/tests/modules/layout_builder_field_block_theme_suggestions_test/layout_builder_field_block_theme_suggestions_test.info.yml rename to core/modules/layout_builder/tests/modules/layout_builder_theme_suggestions_test/layout_builder_theme_suggestions_test.info.yml diff --git a/core/modules/layout_builder/tests/modules/layout_builder_theme_suggestions_test/layout_builder_theme_suggestions_test.module b/core/modules/layout_builder/tests/modules/layout_builder_theme_suggestions_test/layout_builder_theme_suggestions_test.module new file mode 100644 index 0000000000000000000000000000000000000000..1308d4887aab659d51127b84bbd4db0cbe9e434b --- /dev/null +++ b/core/modules/layout_builder/tests/modules/layout_builder_theme_suggestions_test/layout_builder_theme_suggestions_test.module @@ -0,0 +1,30 @@ +<?php + +/** + * @file + * For testing theme suggestions. + */ + +/** + * Implements hook_theme(). + */ +function layout_builder_theme_suggestions_test_theme() { + // It is necessary to explicitly register the template via hook_theme() + // because it is added via a module, not a theme. + return [ + 'field__node__body__bundle_with_section_field__default' => [ + 'base hook' => 'field', + ], + ]; +} + +/** + * Implements hook_preprocess_HOOK() for the list of layouts. + */ +function layout_builder_theme_suggestions_test_preprocess_item_list__layouts(&$variables) { + foreach (array_keys($variables['items']) as $layout_id) { + if (isset($variables['items'][$layout_id]['value']['#title']['icon'])) { + $variables['items'][$layout_id]['value']['#title']['icon'] = ['#markup' => __FUNCTION__]; + } + } +} diff --git a/core/modules/layout_builder/tests/modules/layout_builder_field_block_theme_suggestions_test/templates/field--node--body--bundle-with-section-field--default.html.twig b/core/modules/layout_builder/tests/modules/layout_builder_theme_suggestions_test/templates/field--node--body--bundle-with-section-field--default.html.twig similarity index 100% rename from core/modules/layout_builder/tests/modules/layout_builder_field_block_theme_suggestions_test/templates/field--node--body--bundle-with-section-field--default.html.twig rename to core/modules/layout_builder/tests/modules/layout_builder_theme_suggestions_test/templates/field--node--body--bundle-with-section-field--default.html.twig diff --git a/core/modules/layout_builder/tests/src/Functional/LayoutBuilderFieldBlockThemeSuggestionsTest.php b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderThemeSuggestionsTest.php similarity index 74% rename from core/modules/layout_builder/tests/src/Functional/LayoutBuilderFieldBlockThemeSuggestionsTest.php rename to core/modules/layout_builder/tests/src/Functional/LayoutBuilderThemeSuggestionsTest.php index 9e465fc0c4c4e04acdebe360871f415cc3148d14..3e2eea0846f00e7f0d09c1aa1a02fa94e9a49ffd 100644 --- a/core/modules/layout_builder/tests/src/Functional/LayoutBuilderFieldBlockThemeSuggestionsTest.php +++ b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderThemeSuggestionsTest.php @@ -5,11 +5,11 @@ use Drupal\Tests\BrowserTestBase; /** - * Tests field block template suggestions. + * Tests template suggestions. * * @group layout_builder */ -class LayoutBuilderFieldBlockThemeSuggestionsTest extends BrowserTestBase { +class LayoutBuilderThemeSuggestionsTest extends BrowserTestBase { /** * {@inheritdoc} @@ -17,7 +17,7 @@ class LayoutBuilderFieldBlockThemeSuggestionsTest extends BrowserTestBase { public static $modules = [ 'layout_builder', 'node', - 'layout_builder_field_block_theme_suggestions_test', + 'layout_builder_theme_suggestions_test', ]; /** @@ -54,6 +54,18 @@ protected function setUp() { $this->drupalPostForm(NULL, ['layout[enabled]' => TRUE], 'Save'); } + /** + * Tests alterations of the layout list via preprocess functions. + */ + public function testLayoutListSuggestion() { + $page = $this->getSession()->getPage(); + $assert_session = $this->assertSession(); + + $this->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default/layout'); + $page->clickLink('Add section'); + $assert_session->pageTextContains('layout_builder_theme_suggestions_test_preprocess_item_list__layouts'); + } + /** * Tests that of view mode specific field templates are suggested. */