Follow-up of #3529125: Add content display overrides
EntityViewDisplay::getDisplayInfos (static, public, not covered by any interface, with a weak and confusing array structure) must be replaced by a proper use of Drupal services..
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | 0001-Issue-3542273-Replace-getDisplayInfos-with-proper-se.patch | 11.22 KB | mehak22 |
Issue fork display_builder-3542273
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 commentedCan we use EntityViewDisplay::collectRenderDisplays()?
::getDisplayInfos()returns an array of display information keyed with entity type, then 'modes' and 'bundles'. Example::collectRenderDisplay()returns\Drupal\Core\Entity\Display\EntityViewDisplayInterface[]the display objects to use to render the entities, keyed by entity bundle.So it seems we have the same info.
Comment #4
mehak22 commentedThanks for the issue and the detailed explanation.
From the discussion, it seems that EntityViewDisplay::getDisplayInfos() could be replaced with a more structured approach using services, and possibly EntityViewDisplay::collectRenderDisplays().
I would like to work on this by exploring how getDisplayInfos() is currently used and attempting to refactor it to use collectRenderDisplays() or an appropriate service-based solution.
Please let me know if there are any specific constraints or preferred approaches before I proceed.
Thanks!
Comment #5
pdureau commentedIt was just a guess on my side, it would be nice if it is confirmed to you.
The idea is to use as much as possible the interface we are already implementing instead of creating or extending custom interfaces.
Comment #6
mehak22 commented@pdureau
Thanks for the clarification.
Understood — I will verify whether collectRenderDisplays() can fully replace getDisplayInfos() in this context instead of assuming it directly.
I’ll start by reviewing how getDisplayInfos() is currently used and compare the data structure with what is returned by the existing interfaces, and then attempt a refactor using the appropriate entity display APIs.
I’ll share my findings or a proposed approach shortly.
Thanks!
Comment #7
mehak22 commentedHi,
I have worked on replacing the usage of EntityViewDisplay::getDisplayInfos() with a service-based approach using the entity_type.manager.
Specifically, I am loading entity view displays via:
$this->entityTypeManager()
->getStorage('entity_view_display')
->loadByProperties([
'targetEntityType' => $entity->getEntityTypeId(),
'bundle' => $entity->bundle(),
]);
From these, I derive the available view modes instead of relying on the static helper.
I have updated the relevant controller, routing, and derivative plugin usage accordingly.
I will proceed to create a merge request for review shortly.
Please let me know if there are any preferred approaches or adjustments needed.
Thanks!
Comment #8
mehak22 commentedHi,
I explored replacing `EntityViewDisplay::getDisplayInfos()` with a service-based approach using `entity_view_display` storage.
I have updated the relevant usages to load display configurations via the entity type manager and derive view modes from there.
Due to local environment limitations, I wasn’t able to complete the merge request workflow, so I am attaching a patch for review.
Please let me know if any changes or improvements are needed.
Thanks!
Comment #9
teebeecoder commentedThank you @Mehak, I'll create the merge request and do the review.
Comment #10
teebeecoder commentedComment #11
pdureau commentedThere are a few issues with https://www.drupal.org/files/issues/2026-03-19/0001-Issue-3542273-Replac... including;
EntityViewDisplay::getDisplayInfos()has not been removedOverridesRouteshas been totally replaced by a copy ofEntityViewOverridesControllerSo, it is too soon to make a MR from the patch but I have opened a MR anyway as a starting point.
Comment #13
pdureau commentedWe will be able to do this change after the release of 1.0.0 without breaking our APIs so, as the ticket author, I am proposing to remove it from 1.0.0 scope.
Comment #14
pdureau commentedThe method has been moved to
EntityViewOverrideComment #15
pdureau commentedProposal to review.
EntityViewOverridesController: replaced by an entity query (which add a bit of logic)EntityOverrideViewLocalTask: replaced by an entity query (which simplify the logic by removing a nested loop)OverridesRoutes: replaced by an entity query (which simplify the logic by removing a nested loop)So, we have added a bit of code duplication, but the overall logic is simplified and the API is more tight.
No test has been modified 👍
One playwright job fail but it doesn't seem related to the change.
Comment #16
mogtofu33 commentedThanks, tested and merged.
It removes a public method, so it goes in the RC1 change record. RTBC.
Comment #19
pdureau commentedOK :)