You are here

function lazy_settings_update in Lazy-load 8.2

Same name and namespace in other branches
  1. 8 lazy.module \lazy_settings_update()

Update `lazy.settings.image_fields` value with currently enabled options.

Parameters

array $image_fields: An array of image fields set to use Lazy.

2 calls to lazy_settings_update()
lazy_form_entity_view_display_edit_form_alter in ./lazy.module
Implements hook_form_FORM_BASE_ID_alter().
lazy_preprocess_field in ./lazy.module
Implements template_preprocess_field().

File

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

Code

function lazy_settings_update(array $image_fields) {
  $current_image_fields = \Drupal::config('lazy.settings')
    ->get('image_fields');
  if (!is_array($current_image_fields) || empty($current_image_fields)) {
    $current_image_fields = [];
  }
  $fields = array_merge($current_image_fields, $image_fields);
  foreach ($fields as $field_name => $bool_value) {
    if (!$bool_value) {
      unset($fields[$field_name]);
    }
  }
  \Drupal::service('config.factory')
    ->getEditable('lazy.settings')
    ->set('image_fields', $fields)
    ->save();
}