Issue #3096034 by tim.plunkett, zrpnr: Allow customization of the list of layouts
parent
7732e9d794
commit
e3873ccd41
|
@ -69,8 +69,8 @@ class ChooseSectionController implements ContainerInjectionInterface {
|
|||
$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 @@ class ChooseSectionController implements ContainerInjectionInterface {
|
|||
$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' => [
|
||||
|
|
|
@ -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',
|
||||
],
|
||||
];
|
||||
}
|
|
@ -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__];
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,11 +5,11 @@ namespace Drupal\Tests\layout_builder\Functional;
|
|||
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 @@ class LayoutBuilderFieldBlockThemeSuggestionsTest extends BrowserTestBase {
|
|||
$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.
|
||||
*/
|
Loading…
Reference in New Issue