public function PhotoswipeFieldFormatter::viewElements in PhotoSwipe 8
Same name and namespace in other branches
- 8.2 src/Plugin/Field/FieldFormatter/PhotoswipeFieldFormatter.php \Drupal\photoswipe\Plugin\Field\FieldFormatter\PhotoswipeFieldFormatter::viewElements()
- 3.x src/Plugin/Field/FieldFormatter/PhotoswipeFieldFormatter.php \Drupal\photoswipe\Plugin\Field\FieldFormatter\PhotoswipeFieldFormatter::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
File
- src/
Plugin/ Field/ FieldFormatter/ PhotoswipeFieldFormatter.php, line 159
Class
- PhotoswipeFieldFormatter
- Plugin implementation of the 'photoswipe_field_formatter' formatter.
Namespace
Drupal\photoswipe\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
$settings = $this
->getSettings();
if (!empty($items)) {
\Drupal::service('photoswipe.assets_manager')
->attach($elements);
}
foreach ($items as $delta => $item) {
$elements[$delta] = [
'#theme' => 'photoswipe_image_formatter',
'#item' => $item,
'#display_settings' => $settings,
'#delta' => $delta,
];
}
return $elements;
}