You are here

function layout_builder_install in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/layout_builder/layout_builder.install \layout_builder_install()
  2. 10 core/modules/layout_builder/layout_builder.install \layout_builder_install()

Implements hook_install().

File

core/modules/layout_builder/layout_builder.install, line 17
Contains install and update functions for Layout Builder.

Code

function layout_builder_install() {
  $display_changed = FALSE;
  $displays = LayoutBuilderEntityViewDisplay::loadMultiple();

  /** @var \Drupal\layout_builder\Entity\LayoutEntityDisplayInterface[] $displays */
  foreach ($displays as $display) {

    // Create the first section from any existing Field Layout settings.
    $field_layout = $display
      ->getThirdPartySettings('field_layout');
    if (isset($field_layout['id'])) {
      $field_layout += [
        'settings' => [],
      ];
      $display
        ->enableLayoutBuilder()
        ->appendSection(new Section($field_layout['id'], $field_layout['settings']))
        ->save();
      $display_changed = TRUE;
    }
  }

  // Clear the rendered cache to ensure the new layout builder flow is used.
  // While in many cases the above change will not affect the rendered output,
  // the cacheability metadata will have changed and should be processed to
  // prepare for future changes.
  if ($display_changed) {
    Cache::invalidateTags([
      'rendered',
    ]);
  }
}