annotate core/modules/layout_builder/src/Controller/LayoutRebuildTrait.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents c75dbcec494b
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\layout_builder\Controller;
Chris@0 4
Chris@0 5 use Drupal\Core\Ajax\AjaxResponse;
Chris@0 6 use Drupal\Core\Ajax\CloseDialogCommand;
Chris@0 7 use Drupal\Core\Ajax\ReplaceCommand;
Chris@0 8 use Drupal\layout_builder\SectionStorageInterface;
Chris@0 9
Chris@0 10 /**
Chris@0 11 * Provides AJAX responses to rebuild the Layout Builder.
Chris@0 12 */
Chris@0 13 trait LayoutRebuildTrait {
Chris@0 14
Chris@0 15 /**
Chris@0 16 * Rebuilds the layout.
Chris@0 17 *
Chris@0 18 * @param \Drupal\layout_builder\SectionStorageInterface $section_storage
Chris@0 19 * The section storage.
Chris@0 20 *
Chris@0 21 * @return \Drupal\Core\Ajax\AjaxResponse
Chris@0 22 * An AJAX response to either rebuild the layout and close the dialog, or
Chris@0 23 * reload the page.
Chris@0 24 */
Chris@0 25 protected function rebuildAndClose(SectionStorageInterface $section_storage) {
Chris@0 26 $response = $this->rebuildLayout($section_storage);
Chris@0 27 $response->addCommand(new CloseDialogCommand('#drupal-off-canvas'));
Chris@0 28 return $response;
Chris@0 29 }
Chris@0 30
Chris@0 31 /**
Chris@0 32 * Rebuilds the layout.
Chris@0 33 *
Chris@0 34 * @param \Drupal\layout_builder\SectionStorageInterface $section_storage
Chris@0 35 * The section storage.
Chris@0 36 *
Chris@0 37 * @return \Drupal\Core\Ajax\AjaxResponse
Chris@0 38 * An AJAX response to either rebuild the layout and close the dialog, or
Chris@0 39 * reload the page.
Chris@0 40 */
Chris@0 41 protected function rebuildLayout(SectionStorageInterface $section_storage) {
Chris@0 42 $response = new AjaxResponse();
Chris@5 43 $layout = [
Chris@5 44 '#type' => 'layout_builder',
Chris@5 45 '#section_storage' => $section_storage,
Chris@5 46 ];
Chris@0 47 $response->addCommand(new ReplaceCommand('#layout-builder', $layout));
Chris@0 48 return $response;
Chris@0 49 }
Chris@0 50
Chris@0 51 }