Overrides \Drupal\field\Plugin\Type\Formatter\FormatterBase::viewElements().
Overrides EntityReferenceFormatterBase::viewElements
\Drupal\entity_reference\Plugin\field\formatter\EntityReferenceFormatterBase::viewElements().
public function viewElements(EntityInterface $entity, $langcode, array $items) {
// Remove un-accessible items.
parent::viewElements($entity, $langcode, $items);
$elements = array();
foreach ($items as $delta => $item) {
if ($entity = $item['entity']) {
$label = $entity
->label();
// If the link is to be displayed and the entity has a uri,
// display a link.
if ($this
->getSetting('link') && ($uri = $entity
->uri())) {
$elements[$delta] = array(
'#type' => 'link',
'#title' => $label,
'#href' => $uri['path'],
'#options' => $uri['options'],
);
}
else {
$elements[$delta] = array(
'#markup' => check_plain($label),
);
}
}
}
return $elements;
}