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 DisplayBuildablePluginManager that maps an instance ID to a configured plugin, matching on the instance_prefix the plugin definition already carries.
  • Move callers onto it, then delete checkAccess(), checkInstanceId() and getUrlFromInstanceId() from the interface.
  • Turn getDisplayUrlFromInstanceId() into an instance getSettingsUrl(), and let DisplayReference::$settingsUrl read from it instead of each collectDisplays() passing its own.
  • Fix EntityViewOverride's stub, which returns Url::fromRoute('<front>') — BackButton and InstanceListBuilder send 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.

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

mogtofu33 created an issue. See original summary.

pdureau’s picture

They exist because nothing can answer "which plugin owns this instance ID", so every caller walks the plugin definitions and pokes a class string⋅

Indeed, 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:

    $fields['buildable'] = BaseFieldDefinition::create('plugin')
      ->setSetting('plugin_manager_id', 'plugin.manager.display_buildable')
      ->setRequired(TRUE)
      ->setReadOnly(TRUE);

We can load the buildable directly now. Let's consider this Instance enttiy ID string opaque, as it must be.

pdureau’s picture

This 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.

mogtofu33’s picture

Assigned: mogtofu33 » Unassigned
Status: Needs work » Active
mogtofu33’s picture

mogtofu33’s picture

mogtofu33’s picture

pdureau’s picture

Already done

checkAccess() is already gone from the interface (done in #3573905: Replace DisplayBuildableInterface::checkAccess() by AccessibleInterface::access() )

EntityViewOverride's stub, which returns Url::fromRoute('<front>') — BackButton and InstanceListBuilder send overrides to the front page today

Also done :)

Remaining work

So, we need to address:

  • checkInstanceId() could be removed
  • getUrlFromInstanceId() can be replaced by a non-static getSettingsUrl()
  • getDisplayUrlFromInstanceId() can be replaced by a non-static getDisplayUrl()

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:

  • display_builder_entity_view EntityViewDisplayTest is calling getUrlFromInstanceId()
  • display_builder_entity_view EntityViewOverrideTest is calling getDisplayUrlFromInstanceId()
  • display_builder_ui PatternPresetBuildableTest is calling checkInstanceId(), getUrlFromInstanceId() and getDisplayUrlFromInstanceId()
  • display_builder_views DisplayExtenderTest is calling checkInstanceId() and getUrlFromInstanceId()

No playwright test must change. Absolutely none.

pdureau’s picture

Status: Active » Needs review
Issue tags: +AI-accelerated

Available 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:

DisplayBuildableInterface now extends ConfigurableInterface. Every plugin already inherits it from ConfigurablePluginBase, and it lets the Views and preset callers read IDs from the stored plugin configuration instead of parsing the instance ID.

I guess it is OK.

Some stuff to check during review:

  • IntanceList : because that was some confusion during prompting
  • ConfirmViewsBuilderDeleteForm because not covered by a test

Next 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;

rel replaces Used by
canonical (default) getDisplayUrl() Back button
edit-form getSettingsUrl() Instances panel settings action, instance list Edit
collection getCollectionUrl() Instances panel group heading
add-form getAddUrl() Instances panel add link

This is will allow us to:

  • keep the interface tight
  • get an implementation looking familiar to Drupalers
  • add easily new URL later
  • share the common logic between URL building
  • allow some URL to be the fallback of others

pdureau’s picture

I have opened a second MR. Also green.

1.0.x MR 504 MR 505
PHP LOC (no blank, no comment, no test) 16 711 16 556 16 549
DisplayBuildableInterface instance methods 25 27 24
DisplayBuildableInterface static methods 3 0 0
Diff 1.0.x 19 files
+ 168
− 526
21 files
+ 238
− 625

My personal preference go to MR 505.

pdureau’s picture

Following 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:

csakiistvan’s picture

Assigned: Unassigned » csakiistvan
csakiistvan’s picture

Assigned: csakiistvan » Unassigned
Status: Needs review » Reviewed & tested by the community

✅ 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
  • Changed links, all still resolving correctly: the entity view display Back/Edit URLs no longer carry ?entity=node, and the Views "Edit" link in the instance list now points to /admin/structure/views/view/frontpage/edit/page_1 instead 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.
pdureau’s picture

Issue tags: +Breaking Change (BC)

Big breaking change

pdureau’s picture

Assigned: Unassigned » pdureau

I will rebase (it will be huuuuuge) and fix merge conflicts on both branches.

  • mogtofu33 committed 47c312f7 on 1.0.x authored by pdureau
    task: #3616313 Check static methods on DisplayBuildableInterface
    
    By:...
mogtofu33’s picture

Oups 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.

pdureau’s picture

Assigned: pdureau » Unassigned
Status: Reviewed & tested by the community » Fixed

It 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.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

pdureau’s picture

Status: Fixed » Closed (fixed)

Shipped in beta10 release.