Enable Layout Builder via code in tests when that UI is not being tested

Created on 13 July 2020, almost 5 years ago
Updated 15 March 2024, about 1 year ago

Problem/Motivation

As pointed out in #3091309-37: Broken context-aware block plugins throw an unexpected exception β†’ , there are 3+ ways to enable Layout Builder, often used within the same test class.

Proposed resolution

If the UI itself is what is being tested, use code like

    $this->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default');
    $page->checkField('layout[enabled]');
    $page->pressButton('Save');
    $page->checkField('layout[allow_custom]');
    $page->pressButton('Save');

Otherwise, use code like

    LayoutBuilderEntityViewDisplay::load('node.bundle_with_section_field.default')
      ->enableLayoutBuilder()
      ->setOverridable()
      ->save()

Remaining tasks

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

N/A

πŸ“Œ Task
Status

Fixed

Version

10.3 ✨

Component
Layout builderΒ  β†’

Last updated 2 days ago

Created by

πŸ‡ΊπŸ‡ΈUnited States tim.plunkett Philadelphia

Live updates comments and jobs are added and updated live.
  • Blocks-Layouts

    Blocks and Layouts Initiative. See the #2811175 Add layouts to Drupal issue.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024