public function EntityReferenceIdFormatter::viewElements in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceIdFormatter.php \Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceIdFormatter::viewElements()
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
- core/
lib/ Drupal/ Core/ Field/ Plugin/ Field/ FieldFormatter/ EntityReferenceIdFormatter.php, line 29 - Contains \Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceIdFormatter.
Class
- EntityReferenceIdFormatter
- Plugin implementation of the 'entity reference ID' formatter.
Namespace
Drupal\Core\Field\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = array();
foreach ($this
->getEntitiesToView($items, $langcode) as $delta => $entity) {
if ($entity
->id()) {
$elements[$delta] = array(
'#plain_text' => $entity
->id(),
// Create a cache tag entry for the referenced entity. In the case
// that the referenced entity is deleted, the cache for referring
// entities must be cleared.
'#cache' => array(
'tags' => $entity
->getCacheTags(),
),
);
}
}
return $elements;
}