diff --git a/core/modules/layout_builder/layout_builder.module b/core/modules/layout_builder/layout_builder.module index 2138a045f3..21fcf6d2e1 100644 --- a/core/modules/layout_builder/layout_builder.module +++ b/core/modules/layout_builder/layout_builder.module @@ -5,6 +5,8 @@ * Provides hook implementations for Layout Builder. */ +use Drupal\Core\Config\Entity\ConfigEntityInterface; +use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Url; @@ -63,21 +65,31 @@ function layout_builder_form_entity_form_display_edit_form_alter(&$form, FormSta } /** - * Implements hook_field_config_insert(). + * Implements hook_entity_insert(). */ -function layout_builder_field_config_insert(FieldConfigInterface $field_config) { - // Clear the sample entity for this entity type and bundle. - $sample_entity_generator = \Drupal::service('layout_builder.sample_entity_generator'); - $sample_entity_generator->delete($field_config->getTargetEntityTypeId(), $field_config->getTargetBundle()); - \Drupal::service('plugin.manager.block')->clearCachedDefinitions(); +function layout_builder_entity_insert(EntityInterface $entity) { + if ($entity instanceof FieldConfigInterface) { + // Clear the sample entity for this entity type and bundle. + $sample_entity_generator = \Drupal::service('layout_builder.sample_entity_generator'); + $sample_entity_generator->delete($entity->getTargetEntityTypeId(), $entity->getTargetBundle()); + } + + if ($entity instanceof ConfigEntityInterface) { + \Drupal::service('plugin.manager.block')->clearCachedDefinitions(); + } } /** - * Implements hook_field_config_delete(). + * Implements hook_entity_delete(). */ -function layout_builder_field_config_delete(FieldConfigInterface $field_config) { - // Clear the sample entity for this entity type and bundle. - $sample_entity_generator = \Drupal::service('layout_builder.sample_entity_generator'); - $sample_entity_generator->delete($field_config->getTargetEntityTypeId(), $field_config->getTargetBundle()); - \Drupal::service('plugin.manager.block')->clearCachedDefinitions(); +function layout_builder_entity_delete(EntityInterface $entity) { + if ($entity instanceof FieldConfigInterface) { + // Clear the sample entity for this entity type and bundle. + $sample_entity_generator = \Drupal::service('layout_builder.sample_entity_generator'); + $sample_entity_generator->delete($entity->getTargetEntityTypeId(), $entity->getTargetBundle()); + } + + if ($entity instanceof ConfigEntityInterface) { + \Drupal::service('plugin.manager.block')->clearCachedDefinitions(); + } }