Problem/Motivation
Four methods on DisplayBuildableInterface are still static: checkAccess(), checkInstanceId(), getUrlFromInstanceId() and getDisplayUrlFromInstanceId(). They exist because nothing can answer "which plugin owns this instance ID", so every caller walks the plugin definitions and pokes a class string.
Being static, they cannot receive injected services — every remaining \Drupal::service() call in the buildable plugins is inside one of them — and they cannot be mocked in tests. Two of them also duplicate instance methods that already exist: checkAccess($id, $account) asks what isAllowed($account) asks, and getUrlFromInstanceId($id) returns what getBuilderUrl() returns.
Proposed resolution
- Add a resolver to
DisplayBuildablePluginManagerthat maps an instance ID to a configured plugin, matching on theinstance_prefixthe plugin definition already carries. - Move callers onto it, then delete
checkAccess(),checkInstanceId()andgetUrlFromInstanceId()from the interface. - Turn
getDisplayUrlFromInstanceId()into an instancegetSettingsUrl(), and letDisplayReference::$settingsUrlread from it instead of eachcollectDisplays()passing its own. - Fix
EntityViewOverride's stub, which returnsUrl::fromRoute('<front>')—BackButtonandInstanceListBuildersend overrides to the front page today.
Remaining tasks
- Each plugin needs a way to turn an instance ID into plugin configuration.
checkInstanceId()returns route parameters, which are not the same shape as the constructor's configuration keys. - Call sites:
InstanceAccessControlHandler,BackButton,InstanceListBuilder,ViewsManagementController,ConfirmViewsBuilderDeleteForm,StateButtons,EntityViewDisplayTrait.
API changes
Four methods removed from DisplayBuildableInterface, one added as an instance method. Follows the same de-static work done for collectDisplays(), collectDisplaysBound() and collectInstances() in #3615031.
Issue fork display_builder-3616313
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
pdureau commentedIndeed, and another reason of their introduction was a little "mistake" during the early days of the development: instead of considering Instance entity ID as an opaque string, we have put meaning into it, and we rely on this meaning in
DisplayBuildableInterface::checkInstanceId(),::getDisplayUrlFromInstanceId(),::getUrlFromInstanceId().It is not necessary anymore since the introduction of this field in Instance entity:
We can load the buildable directly now. Let's consider this Instance enttiy ID string opaque, as it must be.
Comment #3
pdureau commentedThis task was also in the scope of #3573905: Replace DisplayBuildableInterface::checkAccess() by AccessibleInterface::access() but this specific part has not been started yet, so we are not overlapping.
Comment #4
mogtofu33 commentedComment #5
mogtofu33 commentedComment #6
mogtofu33 commentedComment #7
mogtofu33 commentedComment #8
mogtofu33 commentedComment #9
pdureau commentedAlready done
checkAccess()is already gone from the interface (done in #3573905: Replace DisplayBuildableInterface::checkAccess() by AccessibleInterface::access() )Also done :)
Remaining work
So, we need to address:
checkInstanceId()could be removedgetUrlFromInstanceId()can be replaced by a non-staticgetSettingsUrl()getDisplayUrlFromInstanceId()can be replaced by a non-staticgetDisplayUrl()Those little changes will impact a lot of files in the sub-modules, because those methods are implemented there and called a but everywhere.
Let's try to do this without updating any test, except the direct calls to the removed methods:
getUrlFromInstanceId()getDisplayUrlFromInstanceId()checkInstanceId(),getUrlFromInstanceId()andgetDisplayUrlFromInstanceId()checkInstanceId()andgetUrlFromInstanceId()No playwright test must change. Absolutely none.
Comment #11
pdureau commentedAvailable for review
Tried with Claude Code.
He did the work according to previous comment. Removing 150 lines of PHP code (comments, blanks and tests excluded). Pipeline is green.
The LLM took a little initiative:
I guess it is OK.
Some stuff to check during review:
IntanceList: because that was some confusion during promptingConfirmViewsBuilderDeleteFormbecause not covered by a testNext step?
We know have 6 non-static methods returning URL objects:
::getCollectionUrl(): ?Url;: The admin page listing every display of this buildable's own kind.::getAddUrl(): ?Url;: Where a new display of this buildable's own kind is added.::getBuilderUrl(): Url;: Get display builder instance URL.::getSettingsUrl(): ?Url;: Where this display's own settings are edited, outside the builder.::getDisplayUrl(): ?Url;: Where the editor goes back to when leaving the builder.::getTranslationUrl(string $langcode): Gets the Display Builder UI URL of a translation.Can we merge the 4 ones without parameter and returning a nullable URL? Taking some inspiration from
EntityInterface::toUrl()?public function toUrl(string $rel = 'canonical'): ?Url;This is will allow us to:
Comment #13
pdureau commentedI have opened a second MR. Also green.
+ 168
− 526
+ 238
− 625
My personal preference go to MR 505.
Comment #14
pdureau commentedFollowing analysis of #3616450: Fold the remaining copies of view-mode naming,, I have also converted the protected
::getPrefix()method from static to instance, to simplify the class by removing reflection and memoization mechanisms.This method was static only because of its usage of
::checkInstanceId(), so it is a good fit for this MR.Pushed in 2 MR:
Comment #15
csakiistvanComment #16
csakiistvan✅ Tested and works — applied MR !505, rebuilt caches, then opened a fresh page layout, node type display, node override and Views display builder: every Back button lands on the same admin page as on 1.0.x, and the instance list, the Views builder list and the Views delete confirmation all load with working links. No regression from removing the static methods.
Notes
?entity=node, and the Views "Edit" link in the instance list now points to/admin/structure/views/view/frontpage/edit/page_1instead of?display=page_1.Warning: Undefined array key "no_ui" in ViewDisplay->isDisplayBuildable()shows on every builder page, both on 1.0.x and with the MR, so it is not related to this change.Comment #17
pdureau commentedBig breaking change
Comment #18
pdureau commentedI will rebase (it will be huuuuuge) and fix merge conflicts on both branches.
Comment #20
mogtofu33 commentedOups missed refresh and your comment, I was already on rebased and merge, sorry. Keeping RTBC and to you if you think there is a problem.
Comment #21
pdureau commentedIt happens sometimes. Don't worry.
I saw you merged the big MR (
3616313-unified-to-url-method), that's cool. It is a big simplification of the codebase.Comment #23
pdureau commentedShipped in beta10 release.