public function BlazyFormatterBlazy::buildElements in Blazy 8.2
Same name and namespace in other branches
- 7 src/Plugin/Field/FieldFormatter/BlazyFormatterBlazy.php \Drupal\blazy\Plugin\Field\FieldFormatter\BlazyFormatterBlazy::buildElements()
Build the Blazy elements.
File
- src/
Plugin/ Field/ FieldFormatter/ BlazyFormatterBlazy.php, line 33
Class
- BlazyFormatterBlazy
- Plugin implementation of the `Blazy File` or `Blazy Image` for Blazy only.
Namespace
Drupal\blazy\Plugin\Field\FieldFormatterCode
public function buildElements(array &$build, $files) {
$settings = $build['settings'];
foreach ($files as $delta => $file) {
/** @var Drupal\image\Plugin\Field\FieldType\ImageItem $item */
$item = $file->_referringItem;
$box = [];
$settings['delta'] = $delta;
$settings['file_tags'] = $file
->getCacheTags();
$settings['type'] = 'image';
$settings['uri'] = $file
->getFileUri();
$box['item'] = $item;
$box['settings'] = $settings;
// Build individual element.
$this
->buildElement($box, $file);
// Build caption if so configured.
if (!empty($settings['caption'])) {
foreach ($settings['caption'] as $caption) {
if ($caption_content = $box['item']->{$caption}) {
$box['captions'][$caption] = [
'#markup' => Xss::filterAdmin($caption_content),
];
}
}
}
// Image with grid, responsive image, lazyLoad, and lightbox supports.
$build[$delta] = $this->formatter
->getBlazy($box);
unset($box);
}
}