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

Created on 13 July 2020, over 4 years ago
Updated 15 March 2024, 8 months 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 about 12 hours 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.

  • First commit to issue fork.
  • Merge request !6426Resolve #3158916 β†’ (Open) created by danielveza
  • Pipeline finished with Failed
    10 months ago
    Total: 604s
    #86437
  • Pipeline finished with Failed
    10 months ago
    Total: 163s
    #86458
  • Pipeline finished with Success
    10 months ago
    Total: 760s
    #86467
  • Status changed to Needs review 10 months ago
  • πŸ‡³πŸ‡ΏNew Zealand danielveza Brisbane, AU

    I've been working on this one, tests are now green. I've done the following:

    • Introduced a new test trait for enabling LB in tests
    • Updated tests to enable LB via the API where possible.

    I tried to keep the scope for this one small, we should open a follow up for converting the rest of the LB tests to use the new trait.

  • Status changed to Needs work 10 months ago
  • πŸ‡¦πŸ‡ΊAustralia mstrelan

    A few nits and one suggested parameter type change.

  • Status changed to Needs review 10 months ago
  • πŸ‡³πŸ‡ΏNew Zealand danielveza Brisbane, AU

    Agreed with all the feedback. Pushed up a new commit to address them.

  • Pipeline finished with Success
    10 months ago
    Total: 682s
    #89189
  • Status changed to RTBC 10 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Refactoring appears good to me. New functions have typehint returns, tests all green so nothing appeared to break.

    • catch β†’ committed 3400d1e6 on 10.3.x
      Issue #3158916 by DanielVeza, tim.plunkett, mstrelan: Enable Layout...
    • catch β†’ committed bb733ec6 on 11.x
      Issue #3158916 by DanielVeza, tim.plunkett, mstrelan: Enable Layout...
  • Status changed to Fixed 9 months ago
  • πŸ‡¬πŸ‡§United Kingdom catch

    Committed/pushed to 11.x and cherry-picked to 10.3.x, thanks!

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024