public function LinkIframeFormatter::viewElements in Link iframe formatter 8
Same name and namespace in other branches
- 2.x src/Plugin/Field/FieldFormatter/LinkIframeFormatter.php \Drupal\link_iframe_formatter\Plugin\Field\FieldFormatter\LinkIframeFormatter::viewElements()
Builds a renderable array for a field value.
Parameters
\Drupal\Core\Field\FieldItemListInterface $items: The field values to be rendered.
string $langcode: The language that should be used to render the field.
Return value
array A renderable array for $items, as an array of child elements keyed by consecutive numeric indexes starting from 0.
Overrides LinkFormatter::viewElements
File
- src/
Plugin/ Field/ FieldFormatter/ LinkIframeFormatter.php, line 90
Class
- LinkIframeFormatter
- Plugin implementation of the 'link_iframe_formatter' formatter.
Namespace
Drupal\link_iframe_formatter\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode) {
$element = [];
$settings = $this
->getSettings();
foreach ($items as $delta => $item) {
// By default use the full URL as the link text.
$url = $this
->buildUrl($item);
$element[$delta] = [
'#theme' => 'link_iframe_formatter',
'#url' => $url,
'#width' => $settings['width'],
'#height' => $settings['height'],
'#class' => $settings['class'],
'#original' => $settings['original'],
'#path' => $url,
];
}
return $element;
}