layout_builder_paragraphs-1.0.x-dev/src/Controller/ModalLayoutRebuildTrait.php
src/Controller/ModalLayoutRebuildTrait.php
<?php
declare(strict_types = 1);
namespace Drupal\layout_builder_paragraphs\Controller;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\CloseDialogCommand;
use Drupal\Core\Ajax\ReplaceCommand;
use Drupal\layout_builder\SectionStorageInterface;
/**
* Provides a trait to rebuild the layout builder page for modals.
*/
trait ModalLayoutRebuildTrait {
/**
* 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);
// Close modal.
$response->addCommand(new CloseDialogCommand('#drupal-modal'));
// Close off-canvas.
$response->addCommand(new CloseDialogCommand('#drupal-off-canvas'));
return $response;
}
}
