Mercurial > hg > isophonics-drupal-site
diff core/modules/layout_builder/src/Controller/LayoutRebuildTrait.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | |
children | af1871eacc83 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/modules/layout_builder/src/Controller/LayoutRebuildTrait.php Mon Apr 23 09:46:53 2018 +0100 @@ -0,0 +1,58 @@ +<?php + +namespace Drupal\layout_builder\Controller; + +use Drupal\Core\Ajax\AjaxResponse; +use Drupal\Core\Ajax\CloseDialogCommand; +use Drupal\Core\Ajax\ReplaceCommand; +use Drupal\layout_builder\SectionStorageInterface; + +/** + * Provides AJAX responses to rebuild the Layout Builder. + * + * @internal + */ +trait LayoutRebuildTrait { + + /** + * The class resolver. + * + * @var \Drupal\Core\DependencyInjection\ClassResolverInterface + */ + protected $classResolver; + + /** + * 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_controller = $this->classResolver->getInstanceFromDefinition(LayoutBuilderController::class); + $layout = $layout_controller->layout($section_storage, TRUE); + $response->addCommand(new ReplaceCommand('#layout-builder', $layout)); + return $response; + } + +}