You are here

class EntityReferenceIdFormatter in Entity reference 8

Plugin implementation of the 'entity-reference ID' formatter.

Plugin annotation


@Plugin(
  id = "entityreference_entity_id",
  module = "entityreference",
  label = @Translation("Entity ID"),
  description = @Translation("Display the ID of the referenced entities."),
  field_types = {
    "entityreference"
  }
)

Hierarchy

Expanded class hierarchy of EntityReferenceIdFormatter

File

lib/Drupal/entityreference/Plugin/field/formatter/EntityReferenceIdFormatter.php, line 29
Definition of Drupal\entityreference\Plugin\field\formatter\EntityReferenceIdFormatter.

Namespace

Drupal\entityreference\Plugin\field\formatter
View source
class EntityReferenceIdFormatter extends EntityReferenceFormatterBase {

  /**
   * Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements().
   */
  public function viewElements(EntityInterface $entity, $langcode, array $items) {
    $elements = array();
    foreach ($items as $delta => $item) {
      $elements[$delta] = array(
        '#markup' => check_plain($item['target_id']),
      );
    }
    return $elements;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityReferenceFormatterBase::prepareView public function Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::prepareView().
EntityReferenceIdFormatter::viewElements public function Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements(). Overrides EntityReferenceFormatterBase::viewElements