function FieldLayoutHooks::modulesInstalled
Implements hook_modules_installed().
Attributes
#[Hook('modules_installed')]
File
-
core/
modules/ field_layout/ src/ Hook/ FieldLayoutHooks.php, line 87
Class
- FieldLayoutHooks
- Hook implementations for field_layout.
Namespace
Drupal\field_layout\HookCode
public function modulesInstalled($modules, bool $is_syncing) : void {
if (!in_array('layout_builder', $modules)) {
return;
}
$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.