You are here

protected static function ImageStyle::replaceImageStyle in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/image/src/Entity/ImageStyle.php \Drupal\image\Entity\ImageStyle::replaceImageStyle()

Update field settings if the image style name is changed.

Parameters

\Drupal\image\ImageStyleInterface $style: The image style.

1 call to ImageStyle::replaceImageStyle()
ImageStyle::postSave in core/modules/image/src/Entity/ImageStyle.php
Acts on a saved entity before the insert or update hook is invoked.

File

core/modules/image/src/Entity/ImageStyle.php, line 148

Class

ImageStyle
Defines an image style configuration entity.

Namespace

Drupal\image\Entity

Code

protected static function replaceImageStyle(ImageStyleInterface $style) {
  if ($style
    ->id() != $style
    ->getOriginalId()) {

    // Loop through all entity displays looking for formatters / widgets using
    // the image style.
    foreach (EntityViewDisplay::loadMultiple() as $display) {
      foreach ($display
        ->getComponents() as $name => $options) {
        if (isset($options['type']) && $options['type'] == 'image' && $options['settings']['image_style'] == $style
          ->getOriginalId()) {
          $options['settings']['image_style'] = $style
            ->id();
          $display
            ->setComponent($name, $options)
            ->save();
        }
      }
    }
    foreach (EntityFormDisplay::loadMultiple() as $display) {
      foreach ($display
        ->getComponents() as $name => $options) {
        if (isset($options['type']) && $options['type'] == 'image_image' && $options['settings']['preview_image_style'] == $style
          ->getOriginalId()) {
          $options['settings']['preview_image_style'] = $style
            ->id();
          $display
            ->setComponent($name, $options)
            ->save();
        }
      }
    }
  }
}