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