CodeExplorer getEntityUrl example
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface
$items,
$langcode) { $elements =
[];
$url = NULL;
$entity =
$items->
getEntity();
$entity_type =
$entity->
getEntityType();
if ($this->
getSetting('link_to_entity'
) && !
$entity->
isNew() &&
$entity_type->
hasLinkTemplate('canonical'
)) { $url =
$this->
getEntityUrl($entity);
} foreach ($items as $delta =>
$item) { $view_value =
$this->
viewValue($item);
if ($url) { $elements[$delta] =
[ '#type' => 'link',
'#title' =>
$view_value,
'#url' =>
$url,
];
}