comparison 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
comparison
equal deleted inserted replaced
13:5fb285c0d0e3 14:1fec387a4317
1 <?php
2
3 namespace Drupal\layout_builder\Controller;
4
5 use Drupal\Core\Ajax\AjaxResponse;
6 use Drupal\Core\Ajax\CloseDialogCommand;
7 use Drupal\Core\Ajax\ReplaceCommand;
8 use Drupal\layout_builder\SectionStorageInterface;
9
10 /**
11 * Provides AJAX responses to rebuild the Layout Builder.
12 *
13 * @internal
14 */
15 trait LayoutRebuildTrait {
16
17 /**
18 * The class resolver.
19 *
20 * @var \Drupal\Core\DependencyInjection\ClassResolverInterface
21 */
22 protected $classResolver;
23
24 /**
25 * Rebuilds the layout.
26 *
27 * @param \Drupal\layout_builder\SectionStorageInterface $section_storage
28 * The section storage.
29 *
30 * @return \Drupal\Core\Ajax\AjaxResponse
31 * An AJAX response to either rebuild the layout and close the dialog, or
32 * reload the page.
33 */
34 protected function rebuildAndClose(SectionStorageInterface $section_storage) {
35 $response = $this->rebuildLayout($section_storage);
36 $response->addCommand(new CloseDialogCommand('#drupal-off-canvas'));
37 return $response;
38 }
39
40 /**
41 * Rebuilds the layout.
42 *
43 * @param \Drupal\layout_builder\SectionStorageInterface $section_storage
44 * The section storage.
45 *
46 * @return \Drupal\Core\Ajax\AjaxResponse
47 * An AJAX response to either rebuild the layout and close the dialog, or
48 * reload the page.
49 */
50 protected function rebuildLayout(SectionStorageInterface $section_storage) {
51 $response = new AjaxResponse();
52 $layout_controller = $this->classResolver->getInstanceFromDefinition(LayoutBuilderController::class);
53 $layout = $layout_controller->layout($section_storage, TRUE);
54 $response->addCommand(new ReplaceCommand('#layout-builder', $layout));
55 return $response;
56 }
57
58 }