1 image.field.inc | image_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) |
Implements hook_field_widget_form().
File
- core/
modules/ image/ image.field.inc, line 440 - Implement an image field, based on the file module's file field.
Code
function image_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
// Add display_field setting to field because file_field_widget_form() assumes it is set.
$field['settings']['display_field'] = 0;
$elements = file_field_widget_form($form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
$settings = $instance['settings'];
foreach (element_children($elements) as $delta) {
// Add adjustment of orientation before resizing because EXIF data is needed.
if ($settings['orientate']) {
$elements[$delta]['#upload_validators']['file_validate_image_orientation'] = array($settings['orientate']);
}
// Add upload resolution validation.
if ($settings['max_dimensions'] || $settings['min_dimensions']) {
$elements[$delta]['#upload_validators']['file_validate_image_resolution'] = array($settings['max_dimensions'], $settings['min_dimensions']);
}
// If not using custom extension validation, ensure this is an image.
$supported_extensions = image_get_supported_extensions();
backdrop_alter('image_supported_extensions', $supported_extensions);
$extensions = isset($elements[$delta]['#upload_validators']['file_validate_extensions'][0]) ? $elements[$delta]['#upload_validators']['file_validate_extensions'][0] : implode(' ', $supported_extensions);
$extensions = array_intersect(explode(' ', $extensions), $supported_extensions);
$elements[$delta]['#upload_validators']['file_validate_extensions'][0] = implode(' ', $extensions);
// Set any view used as a browser.
if (!empty($instance['widget']['settings']['browser_view'])) {
$elements[$delta]['#browser_view'] = $instance['widget']['settings']['browser_view'];
}
// Add all extra functionality provided by the image widget.
$elements[$delta]['#process'][] = 'image_field_widget_process';
}
if ($field['cardinality'] == 1) {
// If there's only one field, return it as delta 0.
if (empty($elements[0]['#default_value']['fid'])) {
$elements[0]['#description'] = theme('file_upload_help', array('description' => field_filter_xss($instance['description']), 'upload_validators' => $elements[0]['#upload_validators']));
}
}
else {
$elements['#file_upload_description'] = theme('file_upload_help', array('upload_validators' => $elements[0]['#upload_validators']));
}
return $elements;
}