3 namespace Drupal\Core\Field\Plugin\Field\FieldFormatter;
5 use Drupal\Core\Field\FieldItemListInterface;
8 * Plugin implementation of the 'entity reference ID' formatter.
11 * id = "entity_reference_entity_id",
12 * label = @Translation("Entity ID"),
13 * description = @Translation("Display the ID of the referenced entities."),
19 class EntityReferenceIdFormatter extends EntityReferenceFormatterBase {
24 public function viewElements(FieldItemListInterface $items, $langcode) {
27 foreach ($this->getEntitiesToView($items, $langcode) as $delta => $entity) {
30 '#plain_text' => $entity->id(),
31 // Create a cache tag entry for the referenced entity. In the case
32 // that the referenced entity is deleted, the cache for referring
33 // entities must be cleared.
35 'tags' => $entity->getCacheTags(),