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.
Issue fork custom_elements-3504944
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
Comment #2
roderikComment #4
roderikThis 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.
I checked the entity_type_alter behavior manually with xdebug enabled, and it does the expected thing:
I only tested with drush. Since the only 'interaction' is with the ModuleInstaller service, drush vs UI install can't make a difference.
Comment #5
roderikComment #8
fagotested it with lupus decoupled - this solves the problem! Code looks great also, thus merged!
Comment #10
roderikDropping 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.)