LazyResponsiveImageFormatter.php in Lazy-load 8.3
File
src/Plugin/Field/FieldFormatter/LazyResponsiveImageFormatter.php
View source
<?php
namespace Drupal\lazy\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\responsive_image\Plugin\Field\FieldFormatter\ResponsiveImageFormatter;
class LazyResponsiveImageFormatter extends ResponsiveImageFormatter {
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = parent::viewElements($items, $langcode);
foreach ($elements as $delta => $element) {
$elements[$delta]['#item_attributes']['data-lazy'] = TRUE;
}
return $elements;
}
public function calculateDependencies() {
$dependencies = parent::calculateDependencies();
$dependencies['module'][] = 'responsive_image';
$dependencies['config'][] = 'lazy.settings';
return $dependencies;
}
}