Skip to content

Commit fea6c51

Browse files
committed
Issue #3007973 by tim.plunkett, lukasss, xopoc, bnjmnm, stompersly: Layout builder prevents the rendering of extra fields (like Links) on pages not using Layout Builder
1 parent 7154acd commit fea6c51

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

core/modules/layout_builder/layout_builder.module

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77

88
use Drupal\Core\Entity\EntityInterface;
99
use Drupal\Core\Form\FormStateInterface;
10+
use Drupal\Core\Render\Element;
1011
use Drupal\Core\Routing\RouteMatchInterface;
1112
use Drupal\Core\Url;
1213
use Drupal\field\FieldConfigInterface;
1314
use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay;
1415
use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplayStorage;
1516
use Drupal\layout_builder\Form\LayoutBuilderEntityViewDisplayForm;
1617
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
17-
use Drupal\layout_builder\Entity\LayoutEntityDisplayInterface;
1818
use Drupal\layout_builder\Plugin\Block\ExtraFieldBlock;
1919
use Drupal\layout_builder\InlineBlockEntityOperations;
2020
use Drupal\Core\Session\AccountInterface;
@@ -106,7 +106,9 @@ function layout_builder_field_config_delete(FieldConfigInterface $field_config)
106106
* @see layout_builder_module_implements_alter()
107107
*/
108108
function layout_builder_entity_view_alter(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display) {
109-
if ($display instanceof LayoutEntityDisplayInterface) {
109+
// Only replace extra fields when Layout Builder has been used to alter the
110+
// build. See \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay::buildMultiple().
111+
if (isset($build['_layout_builder']) && !Element::isEmpty($build['_layout_builder'])) {
110112
/** @var \Drupal\Core\Entity\EntityFieldManagerInterface $field_manager */
111113
$field_manager = \Drupal::service('entity_field.manager');
112114
$extra_fields = $field_manager->getExtraFields($entity->getEntityTypeId(), $entity->bundle());

core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,23 @@ public function testLayoutBuilderChooseBlocksAlter() {
530530
$assert_session->linkExists('Changed');
531531
}
532532

533+
/**
534+
* Tests that extra fields work before and after enabling Layout Builder.
535+
*/
536+
public function testExtraFields() {
537+
$assert_session = $this->assertSession();
538+
539+
$this->drupalLogin($this->drupalCreateUser(['administer node display']));
540+
541+
$this->drupalGet('node');
542+
$assert_session->linkExists('Read more');
543+
544+
$this->drupalPostForm('admin/structure/types/manage/bundle_with_section_field/display/default', ['layout[enabled]' => TRUE], 'Save');
545+
546+
$this->drupalGet('node');
547+
$assert_session->linkExists('Read more');
548+
}
549+
533550
/**
534551
* Tests that deleting a View block used in Layout Builder works.
535552
*/

0 commit comments

Comments
 (0)