needsResponsiveImageLazyLoadFieldUpdate example

'type' => 'image',
      'entity_type' => 'entity_test',
      'field_name' => 'bar',
    ])->save();
    FieldConfig::create([
      'entity_type' => 'entity_test',
      'bundle' => 'entity_test',
      'field_name' => 'bar',
    ])->save();

    $test_view = $this->loadTestView('views.view.test_responsive_images');
    $needs_update = $config_updater->needsResponsiveImageLazyLoadFieldUpdate($test_view);
    $test_view->save();
    $this->assertTrue($needs_update);

    $default_display = $test_view->getDisplay('default');
    self::assertEquals('eager', $default_display['display_options']['fields']['bar']['settings']['image_loading']['attribute']);
  }

  /** * Loads a test view. * * @param string $view_id * The view config ID. * * @return \Drupal\views\ViewEntityInterface * A view entity object. */
return $view_config_updater->needsOembedEagerLoadFieldUpdate($view);
  });
}

/** * Add lazy load options to all responsive image type field configurations. */
function views_post_update_responsive_image_lazy_load(?array &$sandbox = NULL): void {
  /** @var \Drupal\views\ViewsConfigUpdater $view_config_updater */
  $view_config_updater = \Drupal::classResolver(ViewsConfigUpdater::class);
  \Drupal::classResolver(ConfigEntityUpdater::class)->update($sandbox, 'view', function DViewEntityInterface $view) use ($view_config_updater): bool {
    return $view_config_updater->needsResponsiveImageLazyLoadFieldUpdate($view);
  });
}

/** * Update timestamp formatter settings for views. */
function views_post_update_timestamp_formatter(array &$sandbox = NULL): void {
  /** @var \Drupal\views\ViewsConfigUpdater $view_config_updater */
  $view_config_updater = \Drupal::classResolver(ViewsConfigUpdater::class);
  \Drupal::classResolver(ConfigEntityUpdater::class)->update($sandbox, 'view', function DViewEntityInterface $view) use ($view_config_updater): bool {
    return $view_config_updater->needsTimestampFormatterTimeDiffUpdate($view);
  });
Home | Imprint | This part of the site doesn't use cookies.