public function LinkUrl::viewElements in ShrinkTheWeb 8
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 FormatterInterface::viewElements
File
- src/
Plugin/ Field/ FieldFormatter/ LinkUrl.php, line 179
Class
- LinkUrl
- Plugin annotation @FieldFormatter( id = "shrinktheweb_link_url", label = @Translation("[ShrinkTheWeb] URL as link"), field_types = {"link"} )
Namespace
Drupal\shrinktheweb\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode) {
$settings = $this
->getSettings();
$elements = array();
foreach ($items as $delta => $item) {
$url = $item->uri;
$elements[$delta] = array(
'#theme' => 'shrinktheweb_formatter_shrinktheweb_link_url',
'#url' => $url,
'#image_path' => '',
);
if (!empty($settings['custom_width'])) {
$elements[$delta]['#custom_width'] = $settings['custom_width'];
}
if (!empty($settings['full_length'])) {
$elements[$delta]['#full_length'] = $settings['full_length'];
}
if (!empty($settings['max_height'])) {
$elements[$delta]['#max_height'] = $settings['max_height'];
}
if (!empty($settings['native_resolution'])) {
$elements[$delta]['#native_resolution'] = $settings['native_resolution'];
}
if (!empty($settings['widescreen_resolution_y'])) {
$elements[$delta]['#widescreen_resolution_y'] = $settings['widescreen_resolution_y'];
}
if (!empty($settings['delay'])) {
$elements[$delta]['#delay'] = $settings['delay'];
}
if (!empty($settings['quality'])) {
$elements[$delta]['#quality'] = $settings['quality'];
}
}
return $elements;
}