public function GridStackFileFormatterBase::viewElements in GridStack 8
Same name and namespace in other branches
- 8.2 src/Plugin/Field/FieldFormatter/GridStackFileFormatterBase.php \Drupal\gridstack\Plugin\Field\FieldFormatter\GridStackFileFormatterBase::viewElements()
File
- src/
Plugin/ Field/ FieldFormatter/ GridStackFileFormatterBase.php, line 58
Class
- GridStackFileFormatterBase
- Base class for gridstack image and file ER formatters.
Namespace
Drupal\gridstack\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode) {
$files = $this
->getEntitiesToView($items, $langcode);
// Early opt-out if the field is empty.
if (empty($files)) {
return [];
}
// Collects specific settings to this formatter.
$build = [
'settings' => $this
->buildSettings(),
];
$this->formatter
->buildSettings($build, $items);
// Build the elements.
$this
->buildElements($build, $files);
// Supports Blazy multi-breakpoint images if provided.
$this->formatter
->isBlazy($build['settings'], $build['items'][0]);
return $this
->manager()
->build($build);
}