Skip to content

Commit 83bc30a

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
(cherry picked from commit fea6c51)
1 parent 5f1df65 commit 83bc30a

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

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());

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

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

485+
/**
486+
* Tests that extra fields work before and after enabling Layout Builder.
487+
*/
488+
public function testExtraFields() {
489+
$assert_session = $this->assertSession();
490+
491+
$this->drupalLogin($this->drupalCreateUser(['administer node display']));
492+
493+
$this->drupalGet('node');
494+
$assert_session->linkExists('Read more');
495+
496+
$this->drupalPostForm('admin/structure/types/manage/bundle_with_section_field/display/default', ['layout[enabled]' => TRUE], 'Save');
497+
498+
$this->drupalGet('node');
499+
$assert_session->linkExists('Read more');
500+
}
501+
485502
/**
486503
* Tests that deleting a View block used in Layout Builder works.
487504
*/

0 commit comments

Comments
 (0)