EntityFieldRenderer
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.
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 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
Constructs an EntityFieldRenderer object.
The cache contexts associated with this object.
Returns the current renderer.
Returns the entity translation matching the configured row language.
{@inheritdoc}
{@inheritdoc}
{@inheritdoc}
{@inheritdoc}
{@inheritdoc}
Builds the render arrays for all fields of all result rows.
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)
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.
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.
string[]
getCacheTags()
The cache tags associated with this object.
When this object is modified, these cache tags will be invalidated.
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.
protected EntityTranslationRendererBase
getEntityTranslationRenderer()
Returns the current renderer.
FieldableEntityInterface
getEntityTranslation(EntityInterface $entity, ResultRow $row)
Returns the entity translation matching the configured row language.
getEntityTypeId()
{@inheritdoc}
protected
getLanguageManager()
{@inheritdoc}
protected
getView()
{@inheritdoc}
__sleep()
{@inheritdoc}
__wakeup()
{@inheritdoc}
protected
getEntityTypeManager()
{@inheritdoc}
protected
getEntityRepository()
{@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.
protected string[]
getRenderableFieldIds()
Returns a list of names of entity fields to be rendered.