/**
  * Update field settings if the image style name is changed.
  *
  * @param \Drupal\image\ImageStyleInterface $style
  *   The image style.
  */
 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 (entity_load_multiple('entity_view_display') 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 (entity_load_multiple('entity_form_display') 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();
                 }
             }
         }
     }
 }