You are here

function lazy_preprocess_image in Lazy-load 8

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

Implements template_preprocess_image().

File

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

Code

function lazy_preprocess_image(&$variables) {
  if (array_key_exists('data-lazy-load-fields', $variables['attributes'])) {
    unset($variables['attributes']['data-lazy-load-fields']);
    $config = \Drupal::config('lazy.settings')
      ->get();
    $variables['attributes'][$config['src']] = $variables['attributes']['src'];
    $variables['attributes']['src'] = $config['placeholderSrc'];
    $variables['attributes']['class'][] = $config['selector'];
  }
}