Cleanups identified while reviewing
#3615031.
All pre-existing, none blocking that issue. Grouped because the first two touch
the same interface.
1. Add getSettingsUrl(): ?Url to DisplayBuildableInterface
"Where is this display configured, if that page exists" is implemented three
times, each composing a route and guarding it with
RouteNotFoundException:
EntityView::manageDisplayUrl()returnsNULLViewDisplay::viewEditUrl()returns
Url::fromRoute('entity.display_builder_instance.collection')ContextualFormPanel::settingsUrl()returnsNULL
They do not merely duplicate each other, they disagree: three call sites,
three different answers to "there is no such page". All three answer a question
the buildable should answer about itself, and all three already feed
DisplayReference::$settingsUrl from collectDisplays().
An instance-level getSettingsUrl(): ?Url gives one implementation
per plugin and one meaning for absence.
It also removes a null object. getDisplayUrlFromInstanceId() is
contractually non-nullable, so
EntityViewOverride::getDisplayUrlFromInstanceId() returns
Url::fromRoute('<front>) purely to satisfy a signature that
should have allowed NULL.
2. Add DisplayBuildablePluginManager::getDefinitionForInstanceId()
Three callers scan plugin definitions for a matching
instance_prefix, each hand-rolling the same loop:
InstanceAccessControlHandlerEvent\PageVariantSubscriberPlugin\display_builder\Island\BackButton
One manager method replaces all three. It would also let
DisplayBuildablePluginBase::getPrefix() read
$this->pluginDefinition['instance_prefix'] instead of reflecting
over the plugin attribute, dropping the reflection and the per-class
memoization it needs.
3. Fold the remaining copies of view-mode naming
Two places still load entity_view_mode config entities by hand
to name a view mode:
EntityViewOverride::getDisplayInfos(), twice on adjacent
lines, with its own hard-codeddefaultfallbackForm\EntityViewDisplayFormTrait
#3615031 moved the canonical version into
EntityDisplayLabelTrait and switched it to
entity_display.repository, which is cached per entity type and
honors hook_entity_view_mode_info_alter(). That service works from
a static context, which is what makes getDisplayInfos() foldable
now.
See #3616451: Instances listing builds a buildable plugin three times per row for the instances listing performance problem found in
the same pass.
Issue fork display_builder-3616450
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
mogtofu33 commentedComment #3
mogtofu33 commentedComment #4
mogtofu33 commentedComment #5
mogtofu33 commentedComment #6
mogtofu33 commentedComment #7
mogtofu33 commentedComment #8
mogtofu33 commentedComment #9
pdureau commentedThis issue may be outdated.
1. Add
getSettingsUrl(): ?UrltoDisplayBuildableInterfaceThis method is already added in #3616313: Check static methods on DisplayBuildableInterface (and maybe replaced by
::toUrl('edit-form '): ?Url)So, let's skip this one.
2. Add
DisplayBuildablePluginManager::getDefinitionForInstanceId()BackButtonnow calls$builder->getBuildablePlugin(), like the access handler. I am afraidgetDefinitionForInstanceId()would have no callers, and anInstancealways knows its own plugin, which makes reading meaning into the ID unnecessary.Also, the works done in #3616313: Check static methods on DisplayBuildableInterface will allow us to make
::getPrefix()an instance method instead of a static method, resolving this refection/memoization issue.I will do it directly in the other ticket.
3. Fold the remaining copies of view-mode naming
EntityViewOverride::getDisplayInfos()will be removed hopefully (#3542273: Remove EntityViewOverride::getDisplayInfos ) but it is still here for now.So, the idea would be to replace calls to
$entityTypeManager->getStorage('entity_view_mode')by$entityDisplayRepository->getViewModeOptions()?It worth a try. Without any change in phpunit and playwright tests, of course ;)
Comment #11
pdureau commentedComment #12
pdureau commented$entityTypeManager->getStorage('entity_view_mode')has been replaced by$entityDisplayRepository->getViewModeOptions()in:Comment #13
smovs commentedHi team! I've reviewed the MR on my local copy. A few things:
One request before RTBC:
The issue summary points at
EntityDisplayLabelTrait::getViewModeLabel()as the canonical helper to fold the remaining copies into, but the MR inlines agetViewModeOptions()lookup inEntityViewDisplayFormTraitand again inEntityOverrideViewLocalTask. That leaves three copies of the same"options[$mode] ?? $mode"fallback in the submodule. The deriver already injects the repository and both form classes inherit it fromEntityDisplayFormBase, so both can use the trait. The form trait only needs to map 'default' to 'full' before calling it; the helper already names the default mode. For an issue about collapsing duplicates, this seems worth doing here rather than in a follow-up.Two small test nits, non-blocking:
- In
testDefaultDisplayIsNamedAfterFullViewMode, the "if (!EntityViewMode::load(...))"guard is dead:EntityKernelTestBaseinstalls config only for field, so the entity_test full view mode is never present. Creating it unconditionally reads clearer.-
testDefaultDisplayWithoutFullViewModerelies on the user module's config not being installed, but user does ship a full view mode. An explicit assertion that it is absent would make the precondition visible.Comment #14
pdureau commentedHi smovs,
Thanks for your review.
I don't see any reference of
EntityDisplayLabelTrait::getViewModeLabel()in the issue description.It is me who proposed
::getViewModeOptions()and it may not be the best solution. You are warmly welcomed to assign the ticket to you in "Needs work" to propose something more streamlined.Comment #15
smovs commentedThanks @pdureau, you're right, and I was wrong in #13. The summary only says the canonical version is in
EntityDisplayLabelTrait. It doesn't namegetViewModeLabel().I went through the MR again more carefully, with Claude's help this time, and my suggestion doesn't work:
EntityDisplayFormBasealready hasprotected $entityDisplayRepository;without a type. The trait declares it with a type, and PHP stops with a fatal error (we checked this with a small PHP repro of the same class layout).fullfirst, thendefault. The helper doesn't do that.So I'm withdrawing that request. The code is fine as it is.
Two small test suggestions, both optional:
1. In
testDefaultDisplayIsNamedAfterFullViewMode(), theifis always true, because this kernel test never installs theentity_test.fullview mode:2. In
testDefaultDisplayWithoutFullViewMode(), the test depends onuser.fullnot existing. The user module ships that view mode, so asserting it's absent makes the assumption visible:RTBC from me, with or without these.
Comment #16
csakiistvan✅ Tested and works — applied MR !509, rebuilt caches and created the display override field for the
defaultdisplay ofmenu_link_content(nofullview mode) throughEntityViewDisplayForm::createOverrideField(): the field is now labelled "Default display override" instead of failing. The view-mode naming fold also fixes this crash. Suggest to RTBCBefore
After
Notes
4f85b3f8, merge-result pipeline green; the new kernel test covers the crash path, no blocking findings.Comment #17
csakiistvanComment #18
pdureau commentedRebasing because
EntityViewDisplayFormTraithas been removed by #3594228: Remove explicit references to Layout BuilderComment #19
pdureau commentedThe rebase has been heavy and risky, because of the removal of
EntityViewDisplayFormTraitin main branch.However, I am deciding to keep it in RTBC, because:
EntityViewDisplayFormHookfollow the ones previously made inEntityViewDisplayFormTraitEntityViewDisplayFormOverrideFieldTestfrollow the switch fromEntityViewDisplayFormTraittoEntityViewDisplayFormHookEntityOverrideViewLocalTaskandEntityViewOverrideare identicalRTBC version from last week:
4f85b3f8b4060f1b6cafee4496af830d2da51dd0:
I hope it is OK for you.
Pushed today:
9ed6c6ea608d26b471dc7ca5fdc36a43c6d5504b:
Comment #20
mogtofu33 commentedThanks.
Comment #23
pdureau commentedShipped in beta10 release.