Allow to render different view modes per entity type in BuildFieldTrait::buildReferencedEntities

Created on 13 August 2025, about 1 month ago

Problem/Motivation

If you have a entity reference field that references multiple entity bundles types, there is no way to render different view modes per entity bundle.

Steps to reproduce

Add a field to reference paragraph of type text and paragraph of type image gallery, try to render the text paragraphs using the full mode for text, but image thumbnails for image.

Proposed resolution

Chang the $view_mode param signature in:

  protected function buildReferencedEntities(?EntityReferenceFieldItemListInterface $reference_field = NULL, string $view_mode = 'full', ?string $langcode = NULL): array {

and in

  protected function buildEntities(array $entities = [], string $view_mode = 'full', ?string $langcode = NULL): array {

To make $view_mode to be a string or an array. When the array is passed, we can set a list of view modes per entity type.

Alternatively it could be a closure, to have even more control, but not sure this complexity is even necessary.

Remaining tasks

User interface changes

API changes

Data model changes

Feature request
Status

Active

Version

1.1

Component

Code

Created by

🇦🇷Argentina dagmar Argentina

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024