Builds a renderable array for one field on one entity instance.
Drupal\Core\Entity\EntityInterface $entity: The entity being displayed.
string $langcode: The language associated with $items.
array $items: Array of field values already loaded for the entities, keyed by entity id.
array A renderable array for a themed field with its label and all its values.
Overrides FormatterInterface::view
public function view(EntityInterface $entity, $langcode, array $items) {
$field = $this->field;
$instance = $this->instance;
$addition = array();
$elements = $this
->viewElements($entity, $langcode, $items);
if ($elements) {
$entity_type = $entity
->entityType();
$info = array(
'#theme' => 'field',
'#title' => $instance['label'],
'#access' => field_access('view', $field, $entity
->entityType(), $entity),
'#label_display' => $this->label,
'#view_mode' => $this->viewMode,
'#language' => $langcode,
'#field_name' => $field['field_name'],
'#field_type' => $field['type'],
'#field_translatable' => $field['translatable'],
'#entity_type' => $entity_type,
'#bundle' => $entity
->bundle(),
'#object' => $entity,
'#items' => $items,
'#formatter' => $this
->getPluginId(),
);
$addition[$field['field_name']] = array_merge($info, $elements);
}
return $addition;
}