public function ImageZoomFormatter::viewElements in Image Zoom 8.3
Same name and namespace in other branches
- 8.2 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 src/
Plugin/ Field/ FieldFormatter/ ImageZoomGalleryFormatter.php - Builds a renderable array for a field value.
File
- src/
Plugin/ Field/ FieldFormatter/ ImageZoomFormatter.php, line 113
Class
- ImageZoomFormatter
- Image Zoom field formatter for Image fields.
Namespace
Drupal\imagezoom\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode) {
$profile = ImageZoomOptions::load($this
->getSetting('imagezoom_options'));
$options = $profile
->getOptions();
$settings = [
'zoomType' => $options['zoom_type'],
];
if ($options['disable']) {
$settings['responsive'] = TRUE;
$settings['respond'] = [
[
'range' => '0 - ' . $options['disable_width'],
'enabled' => FALSE,
],
];
}
$this->moduleHandler
->alter('imagezoom_settings', $settings);
$elements = [];
foreach ($items as $delta => $item) {
$elements[$delta] = [
'#theme' => 'imagezoom_image',
'#item' => $item,
'#display_style' => $options['display_style'],
'#zoom_style' => $options['zoom_style'],
'#settings' => $settings,
];
}
$elements['#attached'] = [
'library' => [
'imagezoom/elevatezoom',
],
'drupalSettings' => [
'imagezoom' => $settings,
],
];
return $elements;
}