public function SmartCropImageEffect::validateConfigurationForm in Image Effects 8
Same name and namespace in other branches
- 8.3 src/Plugin/ImageEffect/SmartCropImageEffect.php \Drupal\image_effects\Plugin\ImageEffect\SmartCropImageEffect::validateConfigurationForm()
- 8.2 src/Plugin/ImageEffect/SmartCropImageEffect.php \Drupal\image_effects\Plugin\ImageEffect\SmartCropImageEffect::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/ SmartCropImageEffect.php, line 106
Class
- SmartCropImageEffect
- 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) {
$form_state
->setErrorByName('width', $this
->t("A percentage crop can not be wider than the source image."));
}
if (strpos($height, '%') !== FALSE && (int) str_replace('%', '', $height) > 100) {
$form_state
->setErrorByName('height', $this
->t("A percentage crop can not be higher than the source image."));
}
}