Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 /**
|
Chris@0
|
4 * @file
|
Chris@0
|
5 * Contains install and update functions for Layout Builder.
|
Chris@0
|
6 */
|
Chris@0
|
7
|
Chris@0
|
8 use Drupal\Core\Cache\Cache;
|
Chris@0
|
9 use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay;
|
Chris@0
|
10 use Drupal\layout_builder\Section;
|
Chris@0
|
11
|
Chris@0
|
12 /**
|
Chris@0
|
13 * Implements hook_install().
|
Chris@0
|
14 */
|
Chris@0
|
15 function layout_builder_install() {
|
Chris@0
|
16 $displays = LayoutBuilderEntityViewDisplay::loadMultiple();
|
Chris@0
|
17 /** @var \Drupal\layout_builder\Entity\LayoutEntityDisplayInterface[] $displays */
|
Chris@0
|
18 foreach ($displays as $display) {
|
Chris@0
|
19 // Create the first section from any existing Field Layout settings.
|
Chris@0
|
20 $field_layout = $display->getThirdPartySettings('field_layout');
|
Chris@0
|
21 if (isset($field_layout['id'])) {
|
Chris@0
|
22 $field_layout += ['settings' => []];
|
Chris@0
|
23 $display->appendSection(new Section($field_layout['id'], $field_layout['settings']));
|
Chris@0
|
24 }
|
Chris@0
|
25
|
Chris@0
|
26 // Sort the components by weight.
|
Chris@0
|
27 $components = $display->get('content');
|
Chris@0
|
28 uasort($components, 'Drupal\Component\Utility\SortArray::sortByWeightElement');
|
Chris@0
|
29 foreach ($components as $name => $component) {
|
Chris@0
|
30 $display->setComponent($name, $component);
|
Chris@0
|
31 }
|
Chris@0
|
32 $display->save();
|
Chris@0
|
33 }
|
Chris@0
|
34
|
Chris@0
|
35 // Clear the rendered cache to ensure the new layout builder flow is used.
|
Chris@0
|
36 // While in many cases the above change will not affect the rendered output,
|
Chris@0
|
37 // the cacheability metadata will have changed and should be processed to
|
Chris@0
|
38 // prepare for future changes.
|
Chris@0
|
39 Cache::invalidateTags(['rendered']);
|
Chris@0
|
40 }
|