3 namespace Drupal\layout_builder\Controller;
5 use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
6 use Drupal\Core\Layout\LayoutPluginManagerInterface;
7 use Drupal\Core\Plugin\PluginFormInterface;
8 use Drupal\Core\StringTranslation\StringTranslationTrait;
10 use Drupal\layout_builder\SectionStorageInterface;
11 use Symfony\Component\DependencyInjection\ContainerInterface;
14 * Defines a controller to choose a new section.
18 class ChooseSectionController implements ContainerInjectionInterface {
21 use StringTranslationTrait;
26 * @var \Drupal\Core\Layout\LayoutPluginManagerInterface
28 protected $layoutManager;
31 * ChooseSectionController constructor.
33 * @param \Drupal\Core\Layout\LayoutPluginManagerInterface $layout_manager
36 public function __construct(LayoutPluginManagerInterface $layout_manager) {
37 $this->layoutManager = $layout_manager;
43 public static function create(ContainerInterface $container) {
45 $container->get('plugin.manager.core.layout')
50 * Choose a layout plugin to add as a section.
52 * @param \Drupal\layout_builder\SectionStorageInterface $section_storage
53 * The section storage.
55 * The delta of the section to splice.
60 public function build(SectionStorageInterface $section_storage, $delta) {
61 $output['#title'] = $this->t('Choose a layout');
64 foreach ($this->layoutManager->getDefinitions() as $plugin_id => $definition) {
65 $layout = $this->layoutManager->createInstance($plugin_id);
69 $definition->getIcon(60, 80, 1, 3),
71 '#type' => 'container',
72 '#children' => $definition->getLabel(),
75 '#url' => Url::fromRoute(
76 $layout instanceof PluginFormInterface ? 'layout_builder.configure_section' : 'layout_builder.add_section',
78 'section_storage_type' => $section_storage->getStorageType(),
79 'section_storage' => $section_storage->getStorageId(),
81 'plugin_id' => $plugin_id,
85 if ($this->isAjax()) {
86 $item['#attributes']['class'][] = 'use-ajax';
87 $item['#attributes']['data-dialog-type'][] = 'dialog';
88 $item['#attributes']['data-dialog-renderer'][] = 'off_canvas';
92 $output['layouts'] = [
93 '#theme' => 'item_list',