Layout builder cannot recover on missing layout

Created on 18 March 2021, over 4 years ago
Updated 16 July 2023, almost 2 years ago

NOTE: For us this problem occurs with Drupal 8.9.13. I have not confirmed yet if it happens in 9.x.

Problem/Motivation

After renaming a layout, or after switching to a branch where a given layout does not exist, any attempt to fix the layout configuration will fail.

Steps to reproduce

Create a custom layout.
Create a layout builder configuration using that custom layout.
Remove or rename the custom layout.
Attempt to edit the layout builder configuration form, OR try to use "drush cim" to revert to a configuration where this layout was not used.

Expected: Layout builder config can be repaired.
Actual: Error.

The "layout_xyz" plugin does not exist. Valid plugin IDs for Drupal\Core\Layout\LayoutPluginManager are: ...

Proposed resolution

Use try/catch in strategic places to recover from this.

Remaining tasks

See tags

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Layout builder 

Last updated about 1 hour ago

Created by

🇩🇪Germany donquixote

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

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

  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

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.

  • 🇦🇺Australia alex.skrypnyk Melbourne

    This is potentially related to https://www.drupal.org/project/drupal/issues/2860346 🐛 Reset plugin discovery when a module/theme is installed Needs work

    The definitions are cached during a theme install.

    If a theme provides custom layouts and has configuration objects that use those layouts (like `entity_view_display`), the layouts plugin definitions will already be cached and newly installed layouts will not have a chance to be discovered during the process of the theme installation.

    Adding a cache tag that depends on installed extensions resolve this issue.

    In LayoutPluginManager:
    $this->setCacheBackend($cache_backend, $type, ['config:core.extension']);

    Patch attached.

  • 🇧🇪Belgium herved

    For me #20 doesn't work.
    I have a theme that is already installed, and some configs using it (in config_sync).
    When I change a layout machine name and attempt to clear cache and config import, it fails.
    #16 and #3 are working though.

  • 🇨🇭Switzerland boregar

    #20 worked for me on a fresh install with CivicTheme 1.6.2 on Drupal Core 10.2.3. Thanks!

  • 🇺🇸United States Kristen Pol Santa Cruz, CA, USA

    I used patch #20 on Drupal 10.3.0 and CivicTheme 1.7.1 and the fatal error went away.

  • 🇺🇸United States Kristen Pol Santa Cruz, CA, USA

    It would be great if someone wanted to review the different approach in #20, update the issue summary, and add tests :)

  • First commit to issue fork.
  • Pipeline finished with Failed
    5 months ago
    Total: 405s
    #409568
  • Pipeline finished with Failed
    5 months ago
    Total: 114s
    #409582
  • First commit to issue fork.
  • Pipeline finished with Failed
    5 months ago
    Total: 103s
    #417639
  • Pipeline finished with Failed
    5 months ago
    Total: 670s
    #417674
  • Pipeline finished with Failed
    4 months ago
    Total: 371s
    #419664
  • Pipeline finished with Failed
    4 months ago
    Total: 503s
    #445620
  • 🇮🇳India anjaliprasannan

    @joshua1234511 The test is failing in the pipeline. I tried it in the local by following the test steps where I could not find a message as in the test case. Is the test written as per requirement? Should the test be rewrorked on?

  • Status changed to Needs review about 2 months ago
  • 🇮🇳India joshua1234511 Goa

    Reverted the added test. Mock tests are complex to integrate into the layout build scenario for scenario-based execution. Manual testing is required for this fix.

  • Pipeline finished with Success
    about 2 months ago
    Total: 421s
    #491459
  • 🇺🇸United States smustgrave

    Going to disagree that we should have test coverage added but will leave in review.

  • 🇳🇿New Zealand danielveza Brisbane, AU

    This absolutely needs test coverage.

    I haven't thoroughly looked into this issue yet, would it would to have a test module that provides a layout, add that layout to a page, then uninstall that module and verify everything still works as expected? If I get a chance I'll look into this.

  • 🇺🇸United States smustgrave

    For the tests

  • 🇳🇿New Zealand danielveza Brisbane, AU

    I've added test coverage, and also fixed issues where this wasn't working on the default layout or on nodes that did not have overridden layouts (Yay for tests)

    Lets see how the pipeline goes here. I'm a little iffy of how many places we are calling ->hasLayout. I wonder if we can put that in a central place instead.

  • Pipeline finished with Failed
    about 1 month ago
    Total: 474s
    #500427
  • 🇳🇿New Zealand danielveza Brisbane, AU

    Test coverage added and tests are green. I'd be interested to get a second set up eyes on this one. Mainly around this comment.

    I'm a little iffy of how many places we are calling ::hasLayout. I wonder if we can put that in a central place instead.

  • I get this error when installing the new Navigation module. (I'm not using any patches for this issue)

    Drupal\Component\Plugin\Exception\PluginNotFoundException: The "navigation_layout" plugin does not exist.

    This issue is prohibiting me from converting my site to the new module.

  • I applied the MR diff as a patch to my Drupal 10.4 site, and I still get the error.

  • 🇺🇸United States smustgrave

    Per #36

  • Let me know if you need me to provide a stack trace or anything else.

  • First commit to issue fork.
  • 🇫🇷France Grimreaper France 🇫🇷

    Hi,

    I made an addition in getLayoutSettings to avoid it to fail if the layout plugin does not exist.

    This is helpful in case of update like for UI Patterns 1 to UI Patterns 2 upgrade.

    Attaching patch for Composer usage.

Production build 0.71.5 2024