3 namespace Drupal\Tests\layout_builder\Kernel;
5 use Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage;
6 use Drupal\layout_builder\Section;
9 * Ensures that Layout Builder and Field Layout are compatible with each other.
11 * @group layout_builder
13 class LayoutBuilderFieldLayoutCompatibilityTest extends LayoutBuilderCompatibilityTestBase {
18 public static $modules = [
25 protected function setUp() {
29 ->setLayoutId('layout_twocol')
34 * Tests the compatibility of Layout Builder and Field Layout.
36 public function testCompatibility() {
37 // Ensure that the configurable field is shown in the correct region and
38 // that the non-configurable field is shown outside the layout.
40 'field field--name-name field--type-string field--label-hidden field__item',
41 'field field--name-test-field-display-configurable field--type-boolean field--label-above',
42 'clearfix text-formatted field field--name-test-display-configurable field--type-text field--label-above',
43 'clearfix text-formatted field field--name-test-display-non-configurable field--type-text field--label-above',
44 'clearfix text-formatted field field--name-test-display-multiple field--type-text field--label-above',
46 $this->assertFieldAttributes($this->entity, $expected_fields);
47 $this->assertNotEmpty($this->cssSelect('.layout__region--first .field--name-test-display-configurable'));
48 $this->assertNotEmpty($this->cssSelect('.layout__region--first .field--name-test-field-display-configurable'));
49 $this->assertNotEmpty($this->cssSelect('.field--name-test-display-non-configurable'));
50 $this->assertEmpty($this->cssSelect('.layout__region .field--name-test-display-non-configurable'));
52 $this->installLayoutBuilder();
54 // Without using Layout Builder for an override, the result has not changed.
55 $this->assertFieldAttributes($this->entity, $expected_fields);
57 // Add a layout override.
58 $this->enableOverrides();
59 /** @var \Drupal\layout_builder\SectionStorageInterface $field_list */
60 $field_list = $this->entity->get(OverridesSectionStorage::FIELD_NAME);
61 $field_list->appendSection(new Section('layout_onecol'));
62 $this->entity->save();
64 // The rendered entity has now changed. The non-configurable field is shown
65 // outside the layout, the configurable field is not shown at all, and the
66 // layout itself is rendered (but empty).
67 $new_expected_fields = [
68 'field field--name-name field--type-string field--label-hidden field__item',
69 'clearfix text-formatted field field--name-test-display-non-configurable field--type-text field--label-above',
70 'clearfix text-formatted field field--name-test-display-multiple field--type-text field--label-above',
72 $this->assertFieldAttributes($this->entity, $new_expected_fields);
73 $this->assertNotEmpty($this->cssSelect('.layout--onecol'));
75 // Removing the layout restores the original rendering of the entity.
76 $field_list->removeSection(0);
77 $this->entity->save();
78 $this->assertFieldAttributes($this->entity, $expected_fields);