You are here

lazy.install in Lazy-load 8.2

Same filename and directory in other branches
  1. 8.3 lazy.install
  2. 8 lazy.install
  3. 7 lazy.install

Install, update, and uninstall functions for the Lazy-load module.

File

lazy.install
View source
<?php

/**
 * @file
 * Install, update, and uninstall functions for the Lazy-load module.
 */

/**
 * Implements hook_requirements().
 */
function lazy_requirements($phase) {
  $requirements = [];
  if ($phase == 'runtime') {
    $library = Drupal::service('library.discovery')
      ->getLibraryByName('lazy', 'lazy-blazy');
    $has_blazy = FALSE;
    if ($library['js']) {
      foreach ($library['js'] as $js) {
        if ($js['type'] == 'file' && file_exists(DRUPAL_ROOT . '/' . $js['data'])) {
          $has_blazy = TRUE;
        }
      }
    }
    $requirements['blazy'] = [
      'title' => t('bLazy library'),
    ];
    $requirements['blazy']['value'] = $has_blazy ? t('Enabled') : t('Not found');
    $requirements['blazy']['severity'] = $has_blazy ? REQUIREMENT_OK : REQUIREMENT_WARNING;
    if (!$has_blazy) {
      $requirements['blazy']['description'] = t('Lazy-load modules requires the bLazy library. See README.md file for instructions.');
    }
  }
  return $requirements;
}

/**
 * Reset "disabled_paths" configuration to module default.
 */
function lazy_update_8201() {
  $config = \Drupal::service('config.factory')
    ->getEditable('lazy.settings');
  if ($config
    ->get('disabled_paths') === NULL) {
    $config
      ->set('disabled_paths', '/rss.xml');
    return t('The new "disabled_paths" configuration is set to "/rss.xml" (default value).');
  }
  return NULL;
}

/**
 * Reset "image_fields" configuration to module default.
 */
function lazy_update_8202() {
  $config = \Drupal::service('config.factory')
    ->getEditable('lazy.settings');
  if ($config
    ->get('image_fields') === TRUE) {
    $config
      ->set('image_fields', FALSE);
    return t('<b>Action needed:</b> As of 8.x-2.x, image fields are now controlled individually. You need to manually update each image field to enable lazy-loading.');
  }
  return NULL;
}

Functions

Namesort descending Description
lazy_requirements Implements hook_requirements().
lazy_update_8201 Reset "disabled_paths" configuration to module default.
lazy_update_8202 Reset "image_fields" configuration to module default.