function imagefield_crop_widget_preview_process in Imagefield Crop 7.2
Same name and namespace in other branches
- 7.3 imagefield_crop.module \imagefield_crop_widget_preview_process()
- 7 imagefield_crop.module \imagefield_crop_widget_preview_process()
1 string reference to 'imagefield_crop_widget_preview_process'
- imagefield_crop_widget_process in ./
imagefield_crop.module - An element #process callback for the imagefield_crop field type.
File
- ./
imagefield_crop.module, line 822 - Functionality and Drupal hook implementations for the Imagefield Crop module.
Code
function imagefield_crop_widget_preview_process($element, &$form_state, $form) {
$file = $element['#file'];
if ($file->fid == 0) {
return $element;
}
// The widget belongs to the parent, so we got to find it first.
$parents = array_slice($element['#array_parents'], 0, -1);
$parent = drupal_array_get_nested_value($form, $parents);
$instance = field_widget_instance($parent, $form_state);
$context = array(
'form' => $form,
);
drupal_alter('imagefield_crop_instance', $instance, $context);
list($width, $height) = !empty($instance['widget']['settings']['resolution']) ? explode('x', $instance['widget']['settings']['resolution']) : array(
0,
0,
);
if (!empty($instance['widget']['settings']['preview_image_width'])) {
$height = $instance['widget']['settings']['preview_image_width'] / $width * $height;
$width = $instance['widget']['settings']['preview_image_width'];
}
$image_info = image_get_info(drupal_realpath($file->uri));
$settings = array(
$parent['#id'] => array(
'preview' => array(
'orig_width' => $image_info['width'],
'orig_height' => $image_info['height'],
'width' => (int) $width,
'height' => (int) $height,
),
),
);
$element['#attached']['js'][] = array(
'data' => array(
'imagefield_crop' => $settings,
),
'type' => 'setting',
'scope' => 'header',
);
$element['#imagefield_crop'] = array(
'#file' => $element['#file'],
'#width' => $width,
'#height' => $height,
'#path' => file_create_url($file->uri),
);
return $element;
}