Plugin implementation of the 'entity reference ID' formatter.
@FieldFormatter(
id = "entity_reference_entity_id",
module = "entity_reference",
label = @Translation("Entity ID"),
description = @Translation("Display the ID of the referenced entities."),
field_types = {
"entity_reference"
}
)
Expanded class hierarchy of EntityReferenceIdFormatter
class EntityReferenceIdFormatter extends EntityReferenceFormatterBase {
/**
* Overrides \Drupal\entity_reference\Plugin\field\formatter\EntityReferenceFormatterBase::viewElements().
*/
public function viewElements(EntityInterface $entity, $langcode, array $items) {
$elements = array();
foreach ($items as $delta => $item) {
if (!empty($item['entity']) && !empty($item['target_id'])) {
$elements[$delta] = array(
'#markup' => check_plain($item['target_id']),
);
}
}
return $elements;
}
}