You are here

function lazy_preprocess_field in Lazy-load 8.3

Same name and namespace in other branches
  1. 8 lazy.module \lazy_preprocess_field()
  2. 8.2 lazy.module \lazy_preprocess_field()

Implements template_preprocess_field().

File

./lazy.module, line 153
Module file for Lazy-load.

Code

function lazy_preprocess_field(&$variables) {
  $element = $variables['element'];
  if (!empty($element['#third_party_settings']) && !empty($element['#third_party_settings']['lazy']['lazy_image'])) {
    foreach ($variables['items'] as $key => $item) {
      $variables['items'][$key]['content']['#item_attributes']['data-lazy'] = $element['#third_party_settings']['lazy'];
      $item_values = (array) $element[$key]['#item']
        ->getValue();
      if (isset($item_values['target_id'])) {
        $variables['items'][$key]['content']['#item_attributes']['data-lazy']['fid'] = $item_values['target_id'];
      }
    }
  }
}