public function ScaleAndSmartCropImageEffect::validateConfigurationForm in Image Effects 8
Same name and namespace in other branches
- 8.3 src/Plugin/ImageEffect/ScaleAndSmartCropImageEffect.php \Drupal\image_effects\Plugin\ImageEffect\ScaleAndSmartCropImageEffect::validateConfigurationForm()
- 8.2 src/Plugin/ImageEffect/ScaleAndSmartCropImageEffect.php \Drupal\image_effects\Plugin\ImageEffect\ScaleAndSmartCropImageEffect::validateConfigurationForm()
Form validation handler.
Parameters
array $form: An associative array containing the structure of the plugin form as built by static::buildConfigurationForm().
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().
Overrides ConfigurableImageEffectBase::validateConfigurationForm
File
- src/
Plugin/ ImageEffect/ ScaleAndSmartCropImageEffect.php, line 112
Class
- ScaleAndSmartCropImageEffect
- Scale and crop an image preserving the portion with the most entropy.
Namespace
Drupal\image_effects\Plugin\ImageEffectCode
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
parent::validateConfigurationForm($form, $form_state);
$width = $form_state
->getValue('width');
$height = $form_state
->getValue('height');
if ((bool) $width === FALSE && (bool) $height === FALSE) {
$form_state
->setError($form, $this
->t("Either <em>Width</em> or <em>Height</em> must be specified."));
}
if (strpos($width, '%') !== FALSE && (int) str_replace('%', '', $width) > 100 && (bool) $form_state
->getValue('upscale') === FALSE) {
$form_state
->setErrorByName('width', $this
->t("Allow upscaling to have a percentage scale wider than the source image."));
}
if (strpos($height, '%') !== FALSE && (int) str_replace('%', '', $height) > 100 && (bool) $form_state
->getValue('upscale') === FALSE) {
$form_state
->setErrorByName('height', $this
->t("Allow upscaling to have a percentage scale higher than the source image."));
}
}