diff --git a/core/modules/field_layout/field_layout.install b/core/modules/field_layout/field_layout.install index 18875181c9..5956bf1095 100644 --- a/core/modules/field_layout/field_layout.install +++ b/core/modules/field_layout/field_layout.install @@ -40,19 +40,3 @@ function field_layout_uninstall() { // Invalidate the render cache since all content will no longer have a layout. Cache::invalidateTags(['rendered']); } - -/** - * Implements hook_requirements(). - */ -function field_layout_requirements($phase) { - $requirements = []; - if ($phase === 'install') { - if (\Drupal::moduleHandler()->moduleExists('layout_builder')) { - $requirements['field_layout'] = [ - 'description' => t('Field Layout cannot be installed because the Layout Builder module is installed and incompatible.'), - 'severity' => REQUIREMENT_ERROR, - ]; - } - } - return $requirements; -} diff --git a/core/modules/layout_builder/layout_builder.install b/core/modules/layout_builder/layout_builder.install deleted file mode 100644 index 64b64078eb..0000000000 --- a/core/modules/layout_builder/layout_builder.install +++ /dev/null @@ -1,22 +0,0 @@ -moduleExists('field_layout')) { - $requirements['layout_builder'] = [ - 'description' => t('Layout Builder cannot be installed because the Field Layout module is installed and incompatible.'), - 'severity' => REQUIREMENT_ERROR, - ]; - } - } - return $requirements; -} diff --git a/core/modules/layout_builder/layout_builder.module b/core/modules/layout_builder/layout_builder.module index 861db1f3f6..430b92c70f 100644 --- a/core/modules/layout_builder/layout_builder.module +++ b/core/modules/layout_builder/layout_builder.module @@ -37,6 +37,29 @@ function layout_builder_entity_type_alter(array &$entity_types) { } } +/** + * Removes the Layout Builder field both visually and from the #fields handling. + * + * This prevents any interaction with this field. It is rendered directly + * in layout_builder_entity_view_display_alter(). + * + * @internal + */ +function _layout_builder_hide_layout_field(array &$form) { + unset($form['fields']['layout_builder__layout']); + $key = array_search('layout_builder__layout', $form['#fields']); + if ($key !== FALSE) { + unset($form['#fields'][$key]); + } +} + +/** + * Implements hook_form_FORM_ID_alter() for \Drupal\field_ui\Form\EntityFormDisplayEditForm. + */ +function layout_builder_form_entity_form_display_edit_form_alter(&$form, FormStateInterface $form_state) { + _layout_builder_hide_layout_field($form); +} + /** * Implements hook_form_FORM_ID_alter() for \Drupal\field_ui\Form\EntityViewDisplayEditForm. */ @@ -45,14 +68,7 @@ function layout_builder_form_entity_view_display_edit_form_alter(&$form, FormSta $display = $form_state->getFormObject()->getEntity(); $entity_type = \Drupal::entityTypeManager()->getDefinition($display->getTargetEntityTypeId()); - // Remove layout_builder__layout both visually and from the #fields handling. - // This prevents any interaction with this field. It is rendered directly - // in layout_builder_entity_view_display_alter(). - unset($form['fields']['layout_builder__layout']); - $key = array_search('layout_builder__layout', $form['#fields']); - if ($key !== FALSE) { - unset($form['#fields'][$key]); - } + _layout_builder_hide_layout_field($form); // @todo Expand to work for all view modes in // https://www.drupal.org/node/2907413. @@ -151,7 +167,10 @@ function layout_builder_add_layout_section_field($entity_type_id, $bundle, $fiel function layout_builder_entity_view_display_alter(EntityViewDisplayInterface $display, array $context) { if ($display->getThirdPartySetting('layout_builder', 'allow_custom', FALSE)) { // Force the layout to render with no label. - $display->setComponent('layout_builder__layout', ['label' => 'hidden']); + $display->setComponent('layout_builder__layout', [ + 'label' => 'hidden', + 'region' => '__layout_builder', + ]); } else { $display->removeComponent('layout_builder__layout'); @@ -163,6 +182,12 @@ function layout_builder_entity_view_display_alter(EntityViewDisplayInterface $di */ function layout_builder_entity_view_alter(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display) { if ($display->getThirdPartySetting('layout_builder', 'allow_custom', FALSE) && !$entity->layout_builder__layout->isEmpty()) { + // If field layout is active, that is all that needs to be removed. + if (\Drupal::moduleHandler()->moduleExists('field_layout') && isset($build['_field_layout'])) { + unset($build['_field_layout']); + return; + } + /** @var \Drupal\Core\Field\FieldDefinitionInterface[] $field_definitions */ $field_definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions($display->getTargetEntityTypeId(), $display->getTargetBundle()); // Remove all display-configurable fields.