function layout_builder_install

Same name in other branches
  1. 9 core/modules/layout_builder/layout_builder.install \layout_builder_install()
  2. 8.9.x core/modules/layout_builder/layout_builder.install \layout_builder_install()
  3. 11.x core/modules/layout_builder/layout_builder.install \layout_builder_install()

Implements hook_install().

File

core/modules/layout_builder/layout_builder.install, line 16

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',
        ]);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.