ImageStyle::replaceImageStyle

protected static ImageStyle::replaceImageStyle(ImageStyleInterface $style)

Update field settings if the image style name is changed.

Parameters

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

File

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

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 (EntityViewDisplay::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();
        }
      }
    }
  }
}
doc_Drupal
2016-10-29 09:19:33
Comments
Leave a Comment

Please login to continue.