Problem/Motivation

Enabling layout_builder module when custom_elements is already enabled, results in:

  • Fatal error:
    In EntityTypeRepository.php line 111:
                                                                                                                    
      The Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay class does not correspond to an entity type.  
  • layout_builder_install() not being executed, therefore some Field Layout sections not being properly initialized.

Cause

An effect of our hook_entity_type_alter implementation is: no LayoutBuilderEntityViewDisplay::load() calls can ever work.

I guess we treat that as a given. (If any module ever does this, things will just fail fatally. I re-checked Core and no such call is used outside of tests, so we are fine... except...)

layout_builder_install() does a LayoutBuilderEntityViewDisplay::loadMultiple().

This seems to be a long standing issue we never noticed before: neither layout_builder_install() nor applicable ModuleInstaller code seems to have changed for years.

Proposed resolution

Skip the entity_type_alter action until layout_builder_install() has executed.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

roderik created an issue. See original summary.

roderik’s picture

roderik’s picture

Status: Active » Needs review

This needs a review, because the code is 'ugly': I don't see a way to know that "layout_builder is being installed" without hardcoded assumptions. (And that's why the comments are big.)

I think we have no other options / it's fine.

  • It errs on the "safe" side, being: only skip when it encounters the exact Layout Builder classname (while Layout Builder is not actually installed).
  • This does mean: if the class is somehow renamed, the fatal error returns.

I checked the entity_type_alter behavior manually with xdebug enabled, and it does the expected thing:

  • only skips while layout_builder is being installed
  • works normally,
    • at other moments during the 'drush en layout_builder' command
    • in normal operations
    • during install/uninstall of other modules, either with or without layout_builder enabled.

I only tested with drush. Since the only 'interaction' is with the ModuleInstaller service, drush vs UI install can't make a difference.

roderik’s picture

Issue summary: View changes

fago made their first commit to this issue’s fork.

  • fago committed 8fad83c4 on 3.x authored by roderik
    Issue #3504944 by roderik: Fix error when enabling layout_builder
    
fago’s picture

Status: Needs review » Fixed

tested it with lupus decoupled - this solves the problem! Code looks great also, thus merged!

Status: Fixed » Closed (fixed)

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

roderik’s picture

Dropping a reference for people ending up here through e.g. text search, or searching for the origin of the code change:

It seems (I haven't verified) that an underlying bugfix will be made in Core in #3127026: Not possible to override an entity type class multiple times, which makes this change unnecessary. So we can probably back out the code after we depend on 11.[something] minimum.

(Which would be good because, as stated in #4 / the code comments, our fix is not ideal: it relies on implementation details of ModuleInstaller.)