public function LinkPlain::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/ LinkPlain.php, line 179
Class
- LinkPlain
- Plugin annotation @FieldFormatter( id = "shrinktheweb_link_plain", label = @Translation("[ShrinkTheWeb] URL as plain text"), 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;
$title = $item->title;
$elements[$delta] = array(
'#theme' => 'shrinktheweb_formatter_shrinktheweb_link_plain',
'#url' => $url,
'#title' => $title,
'#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;
}