You are here

function image_effects_image_style_presave in Image Effects 8.3

Same name and namespace in other branches
  1. 8 image_effects.module \image_effects_image_style_presave()
  2. 8.2 image_effects.module \image_effects_image_style_presave()

Implements hook_ENTITY_TYPE_presave() for image_style entities.

This hook checks if the image style that is being saved contains any aspect switcher effect that refers to the image style itself. If so, this is a circular reference and we should raise an exception.

File

./image_effects.module, line 186
Provides effects and operations for the Image API.

Code

function image_effects_image_style_presave(ImageStyle $style) {
  $effects = $style
    ->getEffects();
  foreach ($effects as $effect) {
    $effect_data = $effect
      ->getConfiguration()['data'];
    switch ($effect
      ->getPluginId()) {
      case 'image_effects_aspect_switcher':
        if ($style
          ->id() === $effect_data['landscape_image_style']) {
          throw new ConfigValueException("You can not select the {$style->label()} image style itself for the landscape style");
        }
        if ($style
          ->id() === $effect_data['portrait_image_style']) {
          throw new ConfigValueException("You can not select the {$style->label()} image style itself for the portrait style");
        }
        break;
      default:
        continue 2;
    }
  }
}