class EntityFieldRenderer extends RendererBase (View source)

Renders entity fields.

This is used to build render arrays for all entity field values of a view result set sharing the same relationship. An entity translation renderer is used internally to handle entity language properly.

Traits

Trait used to instantiate the view's entity translation renderer.

Provides dependency injection friendly methods for serialization.

Provides a standard way to announce deprecated properties.

Properties

ViewExecutable $view

The view executable wrapping the view storage entity.

from  RendererBase
protected LanguageManagerInterface $languageManager

The language manager.

from  RendererBase
protected EntityTypeInterface $entityType

The type of the entity being rendered.

from  RendererBase
protected array $build

Contains an array of render arrays, one for each rendered entity.

from  RendererBase
protected EntityTranslationRendererBase $entityTranslationRenderer

The renderer to be used to render the entity row.

from  EntityTranslationRenderTrait
protected array $_serviceIds

An array of service IDs keyed by property name used for serialization.

from  DependencySerializationTrait
protected array $_entityStorages

An array of entity type IDs keyed by the property name of their storages.

from  DependencySerializationTrait
protected $deprecatedProperties {@inheritdoc}
protected string $relationship

The relationship being handled.

protected EntityTypeManagerInterface $entityTypeManager

The entity type manager.

protected EntityRepositoryInterface $entityRepository

The entity repository service.

protected int[] $processedRows

A list of indexes of rows whose fields have already been rendered.

Methods

__construct(ViewExecutable $view, string $relationship, LanguageManagerInterface $language_manager, EntityTypeInterface $entity_type, EntityTypeManagerInterface $entity_type_manager, EntityRepositoryInterface $entity_repository = NULL)

Constructs an EntityFieldRenderer object.

int
getCacheMaxAge()

The maximum age for which this object may be cached.

string[]
getCacheContexts()

The cache contexts associated with this object.

string[]
getCacheTags()

The cache tags associated with this object.

query(QueryPluginBase $query, string $relationship = NULL)

Alters the query if needed.

preRender(array $result)

Runs before each entity is rendered.

array
render(ResultRow $row, EntityField $field = NULL)

Renders entity field data.

getEntityTranslation(EntityInterface $entity, ResultRow $row)

Returns the entity translation matching the configured row language.

getEntityTypeId()

{@inheritdoc}

getEntityTypeManager()

{@inheritdoc}

getEntityRepository()

{@inheritdoc}

getLanguageManager()

{@inheritdoc}

getView()

{@inheritdoc}

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

__get($name)

Allows to access deprecated/removed properties.

getEntityManager()

{@inheritdoc}

array
buildFields(array $values)

Builds the render arrays for all fields of all result rows.

string[]
getRenderableFieldIds()

Returns a list of names of entity fields to be rendered.

Details

__construct(ViewExecutable $view, string $relationship, LanguageManagerInterface $language_manager, EntityTypeInterface $entity_type, EntityTypeManagerInterface $entity_type_manager, EntityRepositoryInterface $entity_repository = NULL)

Constructs an EntityFieldRenderer object.

Parameters

ViewExecutable $view

The entity row being rendered.

string $relationship

The relationship to be handled.

LanguageManagerInterface $language_manager

The language manager.

EntityTypeInterface $entity_type

The entity type.

EntityTypeManagerInterface $entity_type_manager

The entity type manager.

EntityRepositoryInterface $entity_repository

The entity repository.

int getCacheMaxAge()

The maximum age for which this object may be cached.

Return Value

int

The maximum time in seconds that this object may be cached.

string[] getCacheContexts()

The cache contexts associated with this object.

These identify a specific variation/representation of the object.

Cache contexts are tokens: placeholders that are converted to cache keys by the @cache_contexts_manager service. The replacement value depends on the request context (the current URL, language, and so on). They're converted before storing an object in cache.

Return Value

string[]

An array of cache context tokens, used to generate a cache ID.

string[] getCacheTags()

The cache tags associated with this object.

When this object is modified, these cache tags will be invalidated.

Return Value

string[]

A set of cache tags.

query(QueryPluginBase $query, string $relationship = NULL)

Alters the query if needed.

Parameters

QueryPluginBase $query

The query to alter.

string $relationship

(optional) The relationship, used by a field.

preRender(array $result)

Runs before each entity is rendered.

Parameters

array $result

The full array of results from the query.

array render(ResultRow $row, EntityField $field = NULL)

Renders entity field data.

Parameters

ResultRow $row

A single row of the query result.

EntityField $field

(optional) A field to be rendered.

Return Value

array

A renderable array for the entity data contained in the result row.

protected EntityTranslationRendererBase getEntityTranslationRenderer()

Returns the current renderer.

Return Value

EntityTranslationRendererBase

The configured renderer.

FieldableEntityInterface getEntityTranslation(EntityInterface $entity, ResultRow $row)

Returns the entity translation matching the configured row language.

Parameters

EntityInterface $entity

The entity object the field value being processed is attached to.

ResultRow $row

The result row the field value being processed belongs to.

Return Value

FieldableEntityInterface

The entity translation object for the specified row.

getEntityTypeId()

{@inheritdoc}

protected getEntityTypeManager()

{@inheritdoc}

protected getEntityRepository()

{@inheritdoc}

protected getLanguageManager()

{@inheritdoc}

protected getView()

{@inheritdoc}

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

__get($name)

Allows to access deprecated/removed properties.

This method must be public.

Parameters

$name

protected getEntityManager()

{@inheritdoc}

protected array buildFields(array $values)

Builds the render arrays for all fields of all result rows.

The output is built using EntityViewDisplay objects to leverage multiple-entity building and ensure a common code path with regular entity view.

  • Each relationship is handled by a separate EntityFieldRenderer instance, since it operates on its own set of entities. This also ensures different entity types are handled separately, as they imply different relationships.
  • Within each relationship, the fields to render are arranged in unique sets containing each field at most once (an EntityViewDisplay can only process a field once with given display options, but a View can contain the same field several times with different display options).
  • For each set of fields, entities are processed by bundle, so that formatters can operate on the proper field definition for the bundle.

Parameters

array $values

An array of all ResultRow objects returned from the query.

Return Value

array

A renderable array for the fields handled by this renderer.

See also

EntityViewDisplay

protected string[] getRenderableFieldIds()

Returns a list of names of entity fields to be rendered.

Return Value

string[]

An associative array of views fields.