5 * Provides hook implementations for Layout Builder.
8 use Drupal\Core\Form\FormStateInterface;
9 use Drupal\Core\Routing\RouteMatchInterface;
11 use Drupal\field\FieldConfigInterface;
12 use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay;
13 use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplayStorage;
14 use Drupal\layout_builder\Form\LayoutBuilderEntityViewDisplayForm;
17 * Implements hook_help().
19 function layout_builder_help($route_name, RouteMatchInterface $route_match) {
20 // Add help text to the Layout Builder UI.
21 if ($route_match->getRouteObject()->getOption('_layout_builder')) {
22 $output = '<p>' . t('This layout builder tool allows you to configure the layout of the main content area.') . '</p>';
23 if (\Drupal::currentUser()->hasPermission('administer blocks')) {
24 $output .= '<p>' . t('To manage other areas of the page, use the <a href="@block-ui">block administration page</a>.', ['@block-ui' => Url::fromRoute('block.admin_display')->toString()]) . '</p>';
27 $output .= '<p>' . t('To manage other areas of the page, use the block administration page.') . '</p>';
32 switch ($route_name) {
33 case 'help.page.layout_builder':
34 $output = '<h3>' . t('About') . '</h3>';
35 $output .= '<p>' . t('Layout Builder provides layout building utility.') . '</p>';
36 $output .= '<p>' . t('For more information, see the <a href=":layout-builder-documentation">online documentation for the Layout Builder module</a>.', [':layout-builder-documentation' => 'https://www.drupal.org/docs/8/core/modules/layout_builder']) . '</p>';
42 * Implements hook_entity_type_alter().
44 function layout_builder_entity_type_alter(array &$entity_types) {
45 /** @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types */
46 $entity_types['entity_view_display']
47 ->setClass(LayoutBuilderEntityViewDisplay::class)
48 ->setStorageClass(LayoutBuilderEntityViewDisplayStorage::class)
49 ->setFormClass('edit', LayoutBuilderEntityViewDisplayForm::class);
53 * Implements hook_form_FORM_ID_alter() for \Drupal\field_ui\Form\EntityFormDisplayEditForm.
55 function layout_builder_form_entity_form_display_edit_form_alter(&$form, FormStateInterface $form_state) {
56 // Hides the Layout Builder field. It is rendered directly in
57 // \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay::buildMultiple().
58 unset($form['fields']['layout_builder__layout']);
59 $key = array_search('layout_builder__layout', $form['#fields']);
61 unset($form['#fields'][$key]);
66 * Implements hook_field_config_insert().
68 function layout_builder_field_config_insert(FieldConfigInterface $field_config) {
69 // Clear the sample entity for this entity type and bundle.
70 $sample_entity_generator = \Drupal::service('layout_builder.sample_entity_generator');
71 $sample_entity_generator->delete($field_config->getTargetEntityTypeId(), $field_config->getTargetBundle());
72 \Drupal::service('plugin.manager.block')->clearCachedDefinitions();
76 * Implements hook_field_config_delete().
78 function layout_builder_field_config_delete(FieldConfigInterface $field_config) {
79 // Clear the sample entity for this entity type and bundle.
80 $sample_entity_generator = \Drupal::service('layout_builder.sample_entity_generator');
81 $sample_entity_generator->delete($field_config->getTargetEntityTypeId(), $field_config->getTargetBundle());
82 \Drupal::service('plugin.manager.block')->clearCachedDefinitions();