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 is called after the field type's implementation of hook_field_prepare_view().
This method operates on multiple entities. The $entities and $items parameters are arrays 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 alterings the $items parameter by reference.
array $entities: Array of entities being displayed, keyed by entity ID.
string $langcode: The language the field values are to be shown in. If no language is provided the current language is used.
array $items: Array of field values for the entities, keyed by entity ID.
Overrides FormatterBase::prepareView
public function prepareView(array $entities, $langcode, array &$items) {
$settings = $this
->getSettings();
foreach ($entities as $id => $entity) {
foreach ($items[$id] as &$item) {
// If available, set custom link text.
if (!empty($settings['title'])) {
$item['title'] = $settings['title'];
}
else {
$item['title'] = $item['value'];
}
}
}
}