You are here

function lazy_is_enabled in Lazy-load 8

Same name and namespace in other branches
  1. 8.2 lazy.module \lazy_is_enabled()

Callback function to check whether lazy is enabled in any text-formats.

Return value

mixed Lazy configuration object if enabled, false otherwise.

2 calls to lazy_is_enabled()
LazyForm::buildForm in src/Form/LazyForm.php
Form constructor.
lazy_page_attachments in ./lazy.module
Implements hook_page_attachments().

File

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

Code

function lazy_is_enabled() {
  $status = [];
  $connection = \Drupal::database();
  $query = $connection
    ->query('SELECT c.name, c.data FROM {config} c WHERE c.name LIKE :format', [
    ':format' => 'filter.format.%',
  ]);
  $filters = $query
    ->fetchAllKeyed();
  foreach ($filters as $key => $filter) {
    $filter = unserialize($filter);
    if (isset($filter['status']) && $filter['status'] && isset($filter['dependencies']['module']) && in_array('lazy', $filter['dependencies']['module'])) {
      $status[$key] = TRUE;
    }
  }
  $config = \Drupal::config('lazy.settings')
    ->get();
  $image_fields = $config['image_fields'];
  if (count($image_fields)) {
    foreach ($image_fields as $field_name => $bool_value) {
      if ($bool_value) {
        $status[$field_name] = TRUE;
      }
    }
  }
  return count($status) ? $config : FALSE;
}