public function ImageZoomFormatter::viewElements in Image Zoom 8.2
Same name and namespace in other branches
- 8.3 src/Plugin/Field/FieldFormatter/ImageZoomFormatter.php \Drupal\imagezoom\Plugin\Field\FieldFormatter\ImageZoomFormatter::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 FormatterInterface::viewElements
1 method overrides ImageZoomFormatter::viewElements()
- ImageZoomGalleryFormatter::viewElements in modules/
imagezoom_gallery/ src/ Plugin/ Field/ FieldFormatter/ ImageZoomGalleryFormatter.php - Builds a renderable array for a field value.
File
- src/
Plugin/ Field/ FieldFormatter/ ImageZoomFormatter.php, line 202
Class
- ImageZoomFormatter
- Image Zoom field formatter for Image fields.
Namespace
Drupal\imagezoom\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode) {
$settings = [
'zoomType' => $this
->getSetting('imagezoom_zoom_type'),
];
if ($this
->getSetting('imagezoom_disable')) {
$settings['responsive'] = TRUE;
$settings['respond'] = [
[
'range' => '0 - ' . $this
->getSetting('imagezoom_disable_width'),
'enabled' => FALSE,
],
];
}
$additonal_settings = $this
->settingsToArray($this
->getSetting('imagezoom_additional'));
$settings += $additonal_settings;
$this->moduleHandler
->alter('imagezoom_settings', $settings);
$elements = [];
foreach ($items as $delta => $item) {
$elements[$delta] = [
'#theme' => 'imagezoom_image',
'#item' => $item,
'#display_style' => $this
->getSetting('imagezoom_display_style'),
'#zoom_style' => $this
->getSetting('imagezoom_zoom_style'),
'#settings' => $settings,
];
}
$elements['#attached'] = [
'library' => [
'imagezoom/elevatezoom',
],
'drupalSettings' => [
'imagezoom' => $settings,
],
];
return $elements;
}