You are here

function image_replace_image_style_presave in Image Replace 8

Implements hook_ENTITY_TYPE_presave().

Save image style name into replace effect settings in order to make the style name available from within image_replace_effect callback.

File

./image_replace.module, line 152
Provides an image style effect replacing the whole image with another one.

Code

function image_replace_image_style_presave(ImageStyleInterface $image_style) {
  $effects = $image_style
    ->get('effects');
  foreach ($image_style
    ->get('effects') as $key => $effect) {
    if ($effect['id'] == 'image_replace') {
      $effects[$key]['data']['image_style'] = $image_style
        ->getName();
    }
  }
  $image_style
    ->set('effects', $effects);
}