Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::view().
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',
'#weight' => $this->weight,
'#title' => $instance['label'],
'#access' => field_access('view', $field, $entity_type, $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;
}