public static function WebformImageResolution::processWebformImageResolution in Webform 6.x
Same name and namespace in other branches
- 8.5 src/Element/WebformImageResolution.php \Drupal\webform\Element\WebformImageResolution::processWebformImageResolution()
Expand a image resolution field into width and height elements.
See also
\Drupal\image\Plugin\Field\FieldType\ImageItem::fieldSettingsForm
File
- src/
Element/ WebformImageResolution.php, line 62
Class
- WebformImageResolution
- Provides a webform image resolution element .
Namespace
Drupal\webform\ElementCode
public static function processWebformImageResolution(&$element, FormStateInterface $form_state, &$complete_form) {
$element['#tree'] = TRUE;
$element['#type'] = 'item';
$element += [
'#description' => t('The maximum allowed image size expressed as WIDTH×HEIGHT (e.g. 640×480). Leave blank for no restriction. If a larger image is uploaded, it will be resized to reflect the given width and height. Resizing images on upload will cause the loss of <a href="http://wikipedia.org/wiki/Exchangeable_image_file_format">EXIF data</a> in the image.'),
'#height_title' => t('Maximum height'),
'#width_title' => t('Maximum width'),
];
$element['container'] = [
'#prefix' => '<div class="container-inline">',
'#suffix' => '</div>',
];
$element['container']['x'] = [
'#type' => 'number',
'#title' => $element['#width_title'],
'#title_display' => 'invisible',
'#value' => empty($element['#value']) ? NULL : $element['#value']['x'],
'#min' => 1,
'#field_suffix' => ' × ',
'#parents' => array_merge($element['#parents'], [
'x',
]),
];
$element['container']['y'] = [
'#type' => 'number',
'#title' => $element['#height_title'],
'#title_display' => 'invisible',
'#value' => empty($element['#value']) ? NULL : $element['#value']['y'],
'#min' => 1,
'#field_suffix' => ' ' . t('pixels'),
'#parents' => array_merge($element['#parents'], [
'y',
]),
];
// Add validate callback.
$element += [
'#element_validate' => [],
];
array_unshift($element['#element_validate'], [
get_called_class(),
'validateWebformImageResolution',
]);
return $element;
}