You are here

function lazy_update_8306 in Lazy-load 8.3

Update all lazy-loading enabled text-formats with carried-over settings.

File

./lazy.install, line 213
Install, update, and uninstall functions for the Lazy-load module.

Code

function lazy_update_8306() {
  $configFactory = \Drupal::configFactory();
  $migration_settings = [];
  $config = $configFactory
    ->getEditable('lazy.settings');
  $alter_tag = $config
    ->get('alter_tag');
  foreach ($alter_tag as $tag => $status) {
    $key = $tag === 'img' ? 'image' : $tag;
    $migration_settings[$key] = (bool) $alter_tag[$tag];
  }
  foreach (filter_formats() as $key => $filter) {
    $filter_configuration = $filter
      ->filters()
      ->getConfiguration();
    if (isset($filter_configuration['lazy_filter'])) {
      $format_settings = $configFactory
        ->getEditable("filter.format.{$key}");
      $format_settings
        ->set('filters.lazy_filter.settings', $migration_settings)
        ->save(TRUE);
    }
  }
  $config
    ->clear('image_fields')
    ->clear('alter_tag')
    ->save(TRUE);
}