Skip to content
EntityReferenceIdFormatter.php 1.23 KiB
Newer Older
 * Contains \Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceIdFormatter.
namespace Drupal\Core\Field\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;

/**
 * Plugin implementation of the 'entity reference ID' formatter.
 *
 *   id = "entity_reference_entity_id",
 *   label = @Translation("Entity ID"),
 *   description = @Translation("Display the ID of the referenced entities."),
 *   field_types = {
 *     "entity_reference"
 *   }
 * )
 */
class EntityReferenceIdFormatter extends EntityReferenceFormatterBase {

  /**
  public function viewElements(FieldItemListInterface $items, $langcode) {
    foreach ($this->getEntitiesToView($items, $langcode) as $delta => $entity) {
          '#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(),