function LayoutBuilderTest::testExtraFields
Same name and namespace in other branches
- 11.x core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php \Drupal\Tests\layout_builder\Functional\LayoutBuilderTest::testExtraFields()
- 10 core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php \Drupal\Tests\layout_builder\Functional\LayoutBuilderTest::testExtraFields()
- 9 core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php \Drupal\Tests\layout_builder\Functional\LayoutBuilderTest::testExtraFields()
- 8.9.x core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php \Drupal\Tests\layout_builder\Functional\LayoutBuilderTest::testExtraFields()
Tests that extra fields work before and after enabling Layout Builder.
File
-
core/
modules/ layout_builder/ tests/ src/ Functional/ LayoutBuilderTest.php, line 451
Class
- LayoutBuilderTest
- Tests the Layout Builder UI.
Namespace
Drupal\Tests\layout_builder\FunctionalCode
public function testExtraFields() : void {
$assert_session = $this->assertSession();
$this->drupalLogin($this->drupalCreateUser([
'configure any layout',
'administer node display',
]));
$this->drupalGet('node');
$assert_session->linkExists('Read more');
$this->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default');
$this->submitForm([
'layout[enabled]' => TRUE,
], 'Save');
// Extra fields display under "Content fields".
$this->drupalGet("admin/structure/types/manage/bundle_with_section_field/display/default/layout");
$this->clickLink('Add block');
$assert_session->elementTextContains('xpath', '//details/summary[contains(text(),"Content fields")]/parent::details', 'Extra label');
$this->drupalGet('node');
$assert_session->linkExists('Read more');
// Consider an extra field hidden by default. Make sure it's not displayed.
$this->drupalGet('node/1');
$assert_session->pageTextNotContains('Extra Field 2 is hidden by default.');
// View the layout and add the extra field that is not visible by default.
$this->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default/layout');
$assert_session->pageTextNotContains('Extra Field 2');
$page = $this->getSession()
->getPage();
$page->clickLink('Add block');
$page->clickLink('Extra Field 2');
$page->pressButton('Add block');
$assert_session->pageTextContains('Extra Field 2');
$page->pressButton('Save layout');
// Confirm that the newly added extra field is visible.
$this->drupalGet('node/1');
$assert_session->pageTextContains('Extra Field 2 is hidden by default.');
// Ensure empty extra field and its container are not rendered.
/* @see \Drupal\layout_builder\Plugin\Block\ExtraFieldBlock::preRenderBlock */
$selector = '.block-extra-field-blocknodebundle-with-section-fieldlayout-builder-test-empty';
$assert_session->elementNotExists('css', $selector);
// Force extra field to render, reload page and ensure presence.
\Drupal::keyValue('test_extra_fields_empty')->set('render_extra_field', TRUE);
Cache::invalidateTags([
'test_extra_fields_empty',
]);
$this->getSession()
->reload();
$assert_session->elementExists('css', $selector);
$assert_session->elementTextContains('css', $selector, 'This extra field is visible because it is not empty.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.