function UriLinkFormatter::viewElements
Same name in other branches
- 9 core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/UriLinkFormatter.php \Drupal\Core\Field\Plugin\Field\FieldFormatter\UriLinkFormatter::viewElements()
- 8.9.x core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/UriLinkFormatter.php \Drupal\Core\Field\Plugin\Field\FieldFormatter\UriLinkFormatter::viewElements()
- 10 core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/UriLinkFormatter.php \Drupal\Core\Field\Plugin\Field\FieldFormatter\UriLinkFormatter::viewElements()
Overrides FormatterInterface::viewElements
File
-
core/
lib/ Drupal/ Core/ Field/ Plugin/ Field/ FieldFormatter/ UriLinkFormatter.php, line 26
Class
- UriLinkFormatter
- Plugin implementation of the 'uri_link' formatter.
Namespace
Drupal\Core\Field\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
foreach ($items as $delta => $item) {
if (!$item->isEmpty()) {
$elements[$delta] = [
'#type' => 'link',
'#url' => Url::fromUri($item->value),
'#title' => $item->value,
];
}
}
return $elements;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.