function ChooseSectionController::build

Same name in other branches
  1. 9 core/modules/layout_builder/src/Controller/ChooseSectionController.php \Drupal\layout_builder\Controller\ChooseSectionController::build()
  2. 8.9.x core/modules/layout_builder/src/Controller/ChooseSectionController.php \Drupal\layout_builder\Controller\ChooseSectionController::build()
  3. 10 core/modules/layout_builder/src/Controller/ChooseSectionController.php \Drupal\layout_builder\Controller\ChooseSectionController::build()

Choose a layout plugin to add as a section.

Parameters

\Drupal\layout_builder\SectionStorageInterface $section_storage: The section storage.

int $delta: The delta of the section to splice.

Return value

array The render array.

1 string reference to 'ChooseSectionController::build'
layout_builder.routing.yml in core/modules/layout_builder/layout_builder.routing.yml
core/modules/layout_builder/layout_builder.routing.yml

File

core/modules/layout_builder/src/Controller/ChooseSectionController.php, line 66

Class

ChooseSectionController
Defines a controller to choose a new section.

Namespace

Drupal\layout_builder\Controller

Code

public function build(SectionStorageInterface $section_storage, int $delta) {
    $items = [];
    $definitions = $this->layoutManager
        ->getFilteredDefinitions('layout_builder', $this->getPopulatedContexts($section_storage), [
        'section_storage' => $section_storage,
    ]);
    foreach ($definitions as $plugin_id => $definition) {
        $layout = $this->layoutManager
            ->createInstance($plugin_id);
        $item = [
            '#type' => 'link',
            '#title' => [
                'icon' => $definition->getIcon(60, 80, 1, 3),
                'label' => [
                    '#type' => 'container',
                    '#children' => $definition->getLabel(),
                ],
            ],
            '#url' => Url::fromRoute($layout instanceof PluginFormInterface ? 'layout_builder.configure_section' : 'layout_builder.add_section', [
                'section_storage_type' => $section_storage->getStorageType(),
                'section_storage' => $section_storage->getStorageId(),
                'delta' => $delta,
                'plugin_id' => $plugin_id,
            ]),
        ];
        if ($this->isAjax()) {
            $item['#attributes']['class'][] = 'use-ajax';
            $item['#attributes']['data-dialog-type'][] = 'dialog';
            $item['#attributes']['data-dialog-renderer'][] = 'off_canvas';
        }
        $items[$plugin_id] = $item;
    }
    $output['layouts'] = [
        '#theme' => 'item_list__layouts',
        '#items' => $items,
        '#attributes' => [
            'class' => [
                'layout-selection',
            ],
            'data-layout-builder-target-highlight-id' => $this->sectionAddHighlightId($delta),
        ],
    ];
    return $output;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.