Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ImageStyle.php

function 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 156

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();
                }
            }
        }
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal