diff --git a/src/Form/ImageStyleGenerator.php b/src/Form/ImageStyleGenerator.php index f26bae8..2bb63e4 100644 --- a/src/Form/ImageStyleGenerator.php +++ b/src/Form/ImageStyleGenerator.php @@ -97,6 +97,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { ]; $options = [ + 'image_scale' => "Scale", 'image_scale_and_crop' => "Scale & Crop", ]; @@ -159,34 +160,67 @@ public function submitForm(array &$form, FormStateInterface $form_state) { foreach ($values['image_style_effects_variations'] as $key => $val) { if ($val) { - foreach ($settings['sizes'] as $size) { - $label = $size['label']; - $w_size = $size['size']; - - $machinename = $values['width'] . "x" . $values['height'] . "__" . $key . "__" . $label; - - if (ImageStyle::load($machinename) == NULL) { // phpcs:ignore - $image_style = ImageStyle::create([ - 'status' => TRUE, - 'name' => $machinename, - 'label' => $machinename, - ]); - - $image_style->addImageEffect([ - 'id' => $key, - 'weight' => 1, - 'data' => [ - 'width' => $w_size, - 'height' => ceil($w_size * $values['height'] / $values['width']), - ], - ]); - - $image_style->save(); - - $responses[] = $machinename; + if ($key == "image_scale") { + foreach ($settings['sizes'] as $size) { + $label = $size['label']; + $w_size = $size['size']; + + $machinename = $key . "__" . $label; + + if (ImageStyle::load($machinename) == NULL) { // phpcs:ignore + $image_style = ImageStyle::create([ + 'status' => TRUE, + 'name' => $machinename, + 'label' => $machinename, + ]); + + $image_style->addImageEffect([ + 'id' => $key, + 'weight' => 1, + 'data' => [ + 'width' => $w_size, + ], + ]); + + $image_style->save(); + + $responses[] = $machinename; + } + else { + $this->messenger()->addWarning("Already exists: " . $machinename); + } } - else { - $this->messenger()->addWarning("Already exists: " . $machinename); + } + else { + foreach ($settings['sizes'] as $size) { + $label = $size['label']; + $w_size = $size['size']; + + $machinename = $values['width'] . "x" . $values['height'] . "__" . $key . "__" . $label; + + if (ImageStyle::load($machinename) == NULL) { // phpcs:ignore + $image_style = ImageStyle::create([ + 'status' => TRUE, + 'name' => $machinename, + 'label' => $machinename, + ]); + + $image_style->addImageEffect([ + 'id' => $key, + 'weight' => 1, + 'data' => [ + 'width' => $w_size, + 'height' => ceil($w_size * $values['height'] / $values['width']), + ], + ]); + + $image_style->save(); + + $responses[] = $machinename; + } + else { + $this->messenger()->addWarning("Already exists: " . $machinename); + } } } }