public function viewElements(FieldItemListInterface
$items,
$langcode) { $elements =
[];
$url = NULL;
// Add support to link to the entity itself.
if ($this->
getSetting('link_to_file'
)) { $url =
$this->fileUrlGenerator->
generate($items->
getEntity()->
getFileUri());
} foreach ($items as $delta =>
$item) { $view_value =
$this->
viewValue($item);
if ($url) { $elements[$delta] =
[ '#type' => 'link',
'#title' =>
$view_value,
'#url' =>
$url,
];
} else { $elements[$delta] =
is_array($view_value) ?
$view_value :
['#markup' =>
$view_value];
} }