Proposed commit message
Issue #1867518 by plach, dawehner, epari.siva, Fabianx, yched, Wim Leers, marcvangend: Leverage entityDisplay to provide fast rendering for fields
Problem/Motivation
Rendering entity fields in views works like the following:
For reach row, and for each entity field execute the following code:
<?php
$entity->$field_name->view();
?>
This creates a lot of temporary objects, as some benchmarks here and in #2342045: Standard views base fields need to use same rendering as Field UI fields, for formatting, access checking, and translation consistency has shown.
Proposed resolution
Based on #1852966: Rework entity display settings around EntityDisplay config entity views could use the entityDisplay object to render with better performance.
Basically, the idea is a View should :
- run its query
- load the corresponding entities and group them by entity type
- for each entity type
- create a runtime EntityViewDisplay object
- render each field for all entities in one pass via
EntityViewDisplay::buildFieldMultiple()
and store the result
- for each row/entity and each field in the row, pick the field renderable array in the $build array.
Remaining tasks
Validate the current solutionWrite a patch- Reviews
User interface changes
None
API changes
Additional methods EntityViewDisplay::buildField()
and EntityViewDisplay::buildFieldMultiple()
that instantiate field formatters on demand without needing an EVD configuration entity.
Beta phase evaluation
Issue category | Task becausethe functionality is not broken |
---|---|
Issue priority | Critical because of the performance improvements introduced. |
Disruption | Disruptive for contributed/custom classes extending \Drupal\views\Plugin\views\field\Field::getItems() . |