Problem/Motivation
While reviewing #3032287: Add the content moderation state widget to the layout builder entity form., @amateescu pointed out that the custom hook being implemented, hook_layout_builder_overrides_entity_form_display_alter has some overlap with with the existing hook hook_entity_form_display_alter.
Using the existing hook means:
- Less APIs, less duplication of concerns.
- Implementors would have to check they are altering the layout builder override display.
Firing and implementing the current hook means:
- An explicit API for dealing with LB override displays, no conditions on displays or context.
Proposed resolution
Right now, for the LB code flow hook_entity_form_display_alter is not fired because EntityFormDisplay::collectRenderDisplay is never called, however efforts could be made to either:
Fire the hook again with the same params.- Add a
$default_fallback = TRUEparameter toEntityFormDisplay::collectRenderDisplay()that allows it to to prevent loading the default display.
Remaining tasks
None.
User interface changes
Nope.
API changes
Nope.
Data model changes
Nope.
Release notes snippet
In 8.70-alpha1 and alpha2 only, the Layout Builder module provided hook_layout_builder_overrides_entity_form_display_alter() to modules extending the Layout Builder user interface. was has been removed in in favor of the generic hook_entity_form_display_alter() hook, so any modules depending on this hook during the alpha phase should be updated to use the new hook. Most sites and modules are not affected by this change.
| Comment | File | Size | Author |
|---|---|---|---|
| #21 | interdiff-21.txt | 5.37 KB | amateescu |
| #21 | 3038442-21.patch | 7.7 KB | amateescu |
| #15 | 3038442-15.patch | 9.67 KB | sam152 |
| #15 | interdiff.txt | 3.71 KB | sam152 |
| #10 | 3038442-10.patch | 7.5 KB | sam152 |
Comments
Comment #2
sam152 commentedI think we could remove the hook before 8.7 beta if we came to a resolution on this issue.
Personally my take is that these things serve sufficiently unique circumstances (ie, the LB overrides display has a unique lifecycle compared to a standard display) that having two hooks makes sense. IMO it's a more discoverable and explicit way to deal with this component of LB.
I do however understand the duplication argument and don't feel very strongly about the previous point, so would be fine with making this adjustment if either of the proposed resolutions were feasible, low-risk changes (in terms of stability of existing features etc) and accepted by a committer in the alpha lifecycle.
Comment #4
sam152 commentedCrediting @amateescu for raising these points and shaping the discussion.
I think @tim.plunkett is also best placed to weigh in here. I wouldn't usually assign an issue, but there is some time sensitivity with this one.
Comment #6
sam152 commentedHere is a first pass at an implementation of this.
The changes in here to
::collectRenderDisplaywould also be useful for #2849279: Make the moderation control form an entity form so that it validates entities before save, which follows a similar pattern to constructing the entity form.Comment #7
amateescu commentedOptional -> optional.
Defaults to FALSE. ;)
How about returning early instead of nesting everything inside this check?
Shouldn't we call it with
$transient = TRUE? :)Comment #8
sam152 commentedWhoops, forgot to actually use the new flag. Adding that in and an assert which would fail if the flag wasn't present.
Comment #9
sam152 commentedWhoops, cross posted with #7.
Maybe we should also introduce
EntityDisplayBase::TRANSIENT_MODEor something?Comment #10
sam152 commented1. Done.
2. Done.
3. I couldn't come up with a better control flow, because we still want the latter part of the function to run, so the hook is called. Open to input here.
4. Addressed in #8, but I'm unsure it's the right solution.
Comment #11
amateescu commentedThis shouldn't be needed because the form operation is already defined as
layout_builderin the entity definition.I don't think we need that IMO,
CUSTOM_MODEdescribes it well and Views uses it for the same use case :)Comment #15
sam152 commentedI think this approach makes more sense. Also fixing the failing test.
Comment #16
tim.plunkettThe naming of
transienthere is coupling WHAT the code does with WHY someone would want to do it.Also, this variable does multiple things:
skipDisplayInitializationto TRUEThe changes within CM and LB look good, so I'm happy with the approach. Just concerned about communicating what this means, and subtly changing how important/necessary CUSTOM_MODE is
Comment #17
sam152 commentedYeah, the alternative would be to simply use
_customas the mode, but in doing so it's not obvious to identify the display actually belongs to the layout builder overrides form.This was the only other thing I came up with to ensure the defaults aren't initialised, however it's problematic in the sense that the mode in the fired hook goes out of sync with the mode the display is instantiated, which is a lot weirder imo.
Not sure if this could be addressed with more documentation or simply another approach.
Thanks for taking a look @tim.plunkett. Unassigning since I was the one who assigned this in #4. Feel free to assign it back if you're working on it.
Comment #18
tim.plunkettI think it mostly needs naming/docs improvements, not necessarily a new implementation.
Comment #19
amateescu commentedI think this is NW now based on Tim's feedback..
Comment #20
sam152 commentedOkay, I think the naming the only outstanding thing then. We could rename the variable to
$transient_and_uninitializedor$empty_transient.Alternatively we could add two flags instead of one:
However that's kind of strange since the initialized flag would only actually apply if a new runtime object was being created, which would be quite a rare case.
Comment #21
amateescu commentedHow about changing the variable name to
$default_fallback(or$load_default?) and make it only about whether we should attempt to load the default display from configuration. This would allow people to save alayout_builderform display in config, and I think that's a feature that we shouldn't try to prevent..Also, I don't think that using
EntityDisplayBase::CUSTOM_MODEas the 'final' mode for the form display object is that problematic, developers have two ways of getting the 'initial' form mode that was requested:EntityDisplayInterface::getOriginalMode()and the$context['form_mode']argument ofhook_entity_form_display_alter().Comment #22
tim.plunkettOh this is so much clearer!
Thanks, this would be great to land in 8.7 before that Layout Builder hook is in the wild.
Comment #23
tim.plunkettComment #24
sam152 commentedAh, custom the '_custom' mode seems okay in this case.
It does however still suffer from the feedback given in #16imo, but if @tim.plunkett is fine with this, all good from me.Edit: reading the feedback again, that isn't actually true! +1 RTBC.
Comment #25
tim.plunkettSince this hook was in 8.7.0-alpha1 we need to write a CR and release note for the removal
Comment #26
amateescu commentedUpdates the IS with a release note and wrote a CR: https://www.drupal.org/node/3042512
Comment #27
xjmMaking the release note a bit clearer about the limited scope of the BC break.
Comment #28
xjmNot a beta target, though. This needs to be committed before the beta phase begins. If it had not landed by today it would simply have needed to follow the deprecation process instead
Comment #31
xjmCommitted to 8.8.x and cherry-picked to 8.7.x. Thanks!
Comment #32
xjmTagging for the release notes. (We'll include this in the beta release notes, but probably will remove it for the 8.7.0 minor notes since the BC break does not affect updates from 8.6.)
Comment #33
xjmOops, also belatedly published the CR.