Loading core/modules/field_layout/src/Hook/FieldLayoutHooks.php +37 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Drupal\field_layout\Hook; use Drupal\Core\Cache\Cache; use Drupal\Core\Entity\ContentEntityFormInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; Loading @@ -13,6 +14,8 @@ use Drupal\field_layout\Form\FieldLayoutEntityViewDisplayEditForm; use Drupal\field_layout\Entity\FieldLayoutEntityFormDisplay; use Drupal\field_layout\Entity\FieldLayoutEntityViewDisplay; use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay; use Drupal\layout_builder\Section; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Hook\Attribute\Hook; Loading Loading @@ -78,4 +81,38 @@ public function formAlter(&$form, FormStateInterface $form_state, $form_id) : vo } } /** * Implements hook_modules_installed(). */ #[Hook('modules_installed')] 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']); } } } } core/modules/layout_builder/layout_builder.install +0 −33 Original line number Diff line number Diff line Loading @@ -5,40 +5,7 @@ * Contains install and update functions for Layout Builder. */ use Drupal\Core\Cache\Cache; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay; use Drupal\layout_builder\Section; /** * Implements hook_install(). */ function layout_builder_install(): void { $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']); } } /** * Implements hook_schema(). Loading Loading
core/modules/field_layout/src/Hook/FieldLayoutHooks.php +37 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Drupal\field_layout\Hook; use Drupal\Core\Cache\Cache; use Drupal\Core\Entity\ContentEntityFormInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; Loading @@ -13,6 +14,8 @@ use Drupal\field_layout\Form\FieldLayoutEntityViewDisplayEditForm; use Drupal\field_layout\Entity\FieldLayoutEntityFormDisplay; use Drupal\field_layout\Entity\FieldLayoutEntityViewDisplay; use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay; use Drupal\layout_builder\Section; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Hook\Attribute\Hook; Loading Loading @@ -78,4 +81,38 @@ public function formAlter(&$form, FormStateInterface $form_state, $form_id) : vo } } /** * Implements hook_modules_installed(). */ #[Hook('modules_installed')] 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']); } } } }
core/modules/layout_builder/layout_builder.install +0 −33 Original line number Diff line number Diff line Loading @@ -5,40 +5,7 @@ * Contains install and update functions for Layout Builder. */ use Drupal\Core\Cache\Cache; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay; use Drupal\layout_builder\Section; /** * Implements hook_install(). */ function layout_builder_install(): void { $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']); } } /** * Implements hook_schema(). Loading