Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. LayoutRebuildTrait.php

trait LayoutRebuildTrait

Provides AJAX responses to rebuild the Layout Builder.

Hierarchy

  • trait \Drupal\layout_builder\Controller\LayoutRebuildTrait
4 files declare their use of LayoutRebuildTrait
ConfigureBlockFormBase.php in core/modules/layout_builder/src/Form/ConfigureBlockFormBase.php
ConfigureSectionForm.php in core/modules/layout_builder/src/Form/ConfigureSectionForm.php
LayoutRebuildConfirmFormBase.php in core/modules/layout_builder/src/Form/LayoutRebuildConfirmFormBase.php
MoveBlockForm.php in core/modules/layout_builder/src/Form/MoveBlockForm.php

File

core/modules/layout_builder/src/Controller/LayoutRebuildTrait.php, line 13

Namespace

Drupal\layout_builder\Controller
View source
trait LayoutRebuildTrait {
    
    /**
     * Rebuilds the layout.
     *
     * @param \Drupal\layout_builder\SectionStorageInterface $section_storage
     *   The section storage.
     *
     * @return \Drupal\Core\Ajax\AjaxResponse
     *   An AJAX response to either rebuild the layout and close the dialog, or
     *   reload the page.
     */
    protected function rebuildAndClose(SectionStorageInterface $section_storage) {
        $response = $this->rebuildLayout($section_storage);
        $response->addCommand(new CloseDialogCommand('#drupal-off-canvas'));
        return $response;
    }
    
    /**
     * Rebuilds the layout.
     *
     * @param \Drupal\layout_builder\SectionStorageInterface $section_storage
     *   The section storage.
     *
     * @return \Drupal\Core\Ajax\AjaxResponse
     *   An AJAX response to either rebuild the layout and close the dialog, or
     *   reload the page.
     */
    protected function rebuildLayout(SectionStorageInterface $section_storage) {
        $response = new AjaxResponse();
        $layout = [
            '#type' => 'layout_builder',
            '#section_storage' => $section_storage,
        ];
        $response->addCommand(new ReplaceCommand('#layout-builder', $layout));
        return $response;
    }

}

Members

Title Sort descending Modifiers Object type Summary
LayoutRebuildTrait::rebuildAndClose protected function Rebuilds the layout.
LayoutRebuildTrait::rebuildLayout protected function Rebuilds the layout.

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal