$summary[] =
$this->
getSetting('link'
) ?
$this->
t('Link to the referenced entity'
) :
$this->
t('No link'
);
return $summary;
} /**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface
$items,
$langcode) { $elements =
[];
$output_as_link =
$this->
getSetting('link'
);
foreach ($this->
getEntitiesToView($items,
$langcode) as $delta =>
$entity) { $label =
$entity->
label();
// If the link is to be displayed and the entity has a uri, display a
// link.
if ($output_as_link && !
$entity->
isNew()) { try { $uri =
$entity->
toUrl();
} catch (UndefinedLinkTemplateException
$e) { // This exception is thrown by \Drupal\Core\Entity\Entity::urlInfo()
// and it means that the entity type doesn't have a link template nor
// a valid "uri_callback", so don't bother trying to output a link for