3 namespace Drupal\Tests\layout_builder\Kernel;
5 use Drupal\layout_builder\Section;
8 * Ensures that Layout Builder and Field Layout are compatible with each other.
10 * @group layout_builder
12 class LayoutBuilderFieldLayoutCompatibilityTest extends LayoutBuilderCompatibilityTestBase {
17 public static $modules = [
24 protected function setUp() {
28 ->setLayoutId('layout_twocol')
33 * Tests the compatibility of Layout Builder and Field Layout.
35 public function testCompatibility() {
36 // Ensure that the configurable field is shown in the correct region and
37 // that the non-configurable field is shown outside the layout.
39 'field field--name-name field--type-string field--label-hidden field__item',
40 'field field--name-test-field-display-configurable field--type-boolean field--label-above',
41 'clearfix text-formatted field field--name-test-display-configurable field--type-text field--label-above',
42 'clearfix text-formatted field field--name-test-display-non-configurable field--type-text field--label-above',
43 'clearfix text-formatted field field--name-test-display-multiple field--type-text field--label-above',
45 $this->assertFieldAttributes($this->entity, $expected_fields);
46 $this->assertNotEmpty($this->cssSelect('.layout__region--first .field--name-test-display-configurable'));
47 $this->assertNotEmpty($this->cssSelect('.layout__region--first .field--name-test-field-display-configurable'));
48 $this->assertNotEmpty($this->cssSelect('.field--name-test-display-non-configurable'));
49 $this->assertEmpty($this->cssSelect('.layout__region .field--name-test-display-non-configurable'));
51 $this->installLayoutBuilder();
53 // Without using Layout Builder for an override, the result has not changed.
54 $this->assertFieldAttributes($this->entity, $expected_fields);
56 // Add a layout override.
57 $this->enableOverrides();
58 /** @var \Drupal\layout_builder\SectionStorageInterface $field_list */
59 $field_list = $this->entity->get('layout_builder__layout');
60 $field_list->appendSection(new Section('layout_onecol'));
61 $this->entity->save();
63 // The rendered entity has now changed. The non-configurable field is shown
64 // outside the layout, the configurable field is not shown at all, and the
65 // layout itself is rendered (but empty).
66 $new_expected_fields = [
67 'field field--name-name field--type-string field--label-hidden field__item',
68 'clearfix text-formatted field field--name-test-display-non-configurable field--type-text field--label-above',
69 'clearfix text-formatted field field--name-test-display-multiple field--type-text field--label-above',
71 $this->assertFieldAttributes($this->entity, $new_expected_fields);
72 $this->assertNotEmpty($this->cssSelect('.layout--onecol'));
74 // Removing the layout restores the original rendering of the entity.
75 $field_list->removeSection(0);
76 $this->entity->save();
77 $this->assertFieldAttributes($this->entity, $expected_fields);