public function RelationEndpointFullFormatter::viewElements in Relation 8
Builds a renderable array for a field value.
Parameters
\Drupal\Core\Field\FieldItemListInterface $items: The field values to be rendered.
string $langcode: The language that should be used to render the field.
Return value
array A renderable array for $items, as an array of child elements keyed by consecutive numeric indexes starting from 0.
Overrides FormatterInterface::viewElements
File
- relation_endpoint/
src/ Plugin/ Field/ FieldFormatter/ RelationEndpointFullFormatter.php, line 30 - Contains \Drupal\relation_endpoint\Plugin\Field\FieldFormatter\RelationEndpointFullFormatter.
Class
- RelationEndpointFullFormatter
- Plugin implementation of the 'link' formatter.
Namespace
Drupal\relation_endpoint\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode) {
$build = [];
foreach ($items as $delta => $item) {
$storage_handler = \Drupal::entityTypeManager()
->getStorage($item->entity_type);
if ($entity = $storage_handler
->load($item->entity_id)) {
// @todo: allow view mode customisation.
$build[$delta] = \Drupal::entityTypeManager()
->getViewBuilder($entity
->getEntityTypeId())
->view($entity, 'teaser');
}
}
return $build;
}