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