public static function WebformImageResolution::validateWebformImageResolution in Webform 6.x
Same name and namespace in other branches
- 8.5 src/Element/WebformImageResolution.php \Drupal\webform\Element\WebformImageResolution::validateWebformImageResolution()
Validates an image resolution element.
See also
\Drupal\image\Plugin\Field\FieldType\ImageItem::validateResolution
File
- src/
Element/ WebformImageResolution.php, line 106
Class
- WebformImageResolution
- Provides a webform image resolution element .
Namespace
Drupal\webform\ElementCode
public static function validateWebformImageResolution(&$element, FormStateInterface $form_state, &$complete_form) {
if (!empty($element['container']['x']['#value']) || !empty($element['container']['y']['#value'])) {
foreach ([
'x',
'y',
] as $dimension) {
if (!$element['container'][$dimension]['#value']) {
// We expect the field name placeholder value to be wrapped in t()
// here, so it won't be escaped again as it's already marked safe.
$form_state
->setError($element['container'][$dimension], t('Both a height and width value must be specified in the @name field.', [
'@name' => $element['#title'],
]));
return;
}
}
$form_state
->setValueForElement($element, $element['container']['x']['#value'] . 'x' . $element['container']['y']['#value']);
}
else {
$form_state
->setValueForElement($element, '');
}
}