You are here

public function FormatterBase::prepareView in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Field/FormatterBase.php \Drupal\Core\Field\FormatterBase::prepareView()
  2. 10 core/lib/Drupal/Core/Field/FormatterBase.php \Drupal\Core\Field\FormatterBase::prepareView()

Allows formatters to load information for field values being displayed.

This should be used when a formatter needs to load additional information from the database in order to render a field, for example a reference field that displays properties of the referenced entities such as name or type.

This method operates on multiple entities. The $entities_items parameter is an array keyed by entity ID. For performance reasons, information for all involved entities should be loaded in a single query where possible.

Changes or additions to field values are done by directly altering the items.

Parameters

\Drupal\Core\Field\FieldItemListInterface[] $entities_items: An array with the field values from the multiple entities being rendered.

Overrides FormatterInterface::prepareView

2 methods override FormatterBase::prepareView()
EntityReferenceFormatterBase::prepareView in core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceFormatterBase.php
Loads the entities referenced in that field across all the entities being viewed.
TestFieldPrepareViewFormatter::prepareView in core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldPrepareViewFormatter.php
Allows formatters to load information for field values being displayed.

File

core/lib/Drupal/Core/Field/FormatterBase.php, line 138

Class

FormatterBase
Base class for 'Field formatter' plugin implementations.

Namespace

Drupal\Core\Field

Code

public function prepareView(array $entities_items) {
}