function simplecrop_field_widget_change_display_submit in SimpleCrop 7
Crop submit callback. Switches between displays and saves crop data.
1 string reference to 'simplecrop_field_widget_change_display_submit'
- simplecrop_field_widget_process in includes/
simplecrop.field.inc - Element #process callback for the image_image field type.
File
- includes/
simplecrop.field.inc, line 557 - Contains information about field widget and related functions.
Code
function simplecrop_field_widget_change_display_submit(&$form, &$form_state) {
// Get parents array of triggered button
$image_parents = $form_state['triggering_element']['#parents'];
// Remove name of triggered button.
array_pop($image_parents);
// Get image field value.
$value = drupal_array_get_nested_value($form_state['values'], $image_parents);
// Switch current display.
$display =& $form_state['simplecrop'][$value['fid']]['display'];
$display = $display == SIMPLECROP_DISPLAY_ORIGINAL_IMAGE ? SIMPLECROP_DISPLAY_CROPPED_IMAGE : SIMPLECROP_DISPLAY_ORIGINAL_IMAGE;
// Do some actions after switching from image with crop selection
// to cropped image display.
if ($display == SIMPLECROP_DISPLAY_CROPPED_IMAGE) {
// It makes sense to rebuild crop area coordinates only when
// we switched from original display, because other display
// doesn't contain crop area selection.
// Ensure that we have all required data to save the crop.
if (!empty($value['data']) && !empty($value['scaled_size']) && !empty($value['original_size']) && !empty($value['fid'])) {
$crop =& $form_state['simplecrop'][$value['fid']]['crop'];
// Unscale coordinates from scaled image to original.
$crop['x'] = round($value['original_size']['width'] / $value['scaled_size']['width'] * $value['data']['x']);
$crop['y'] = round($value['original_size']['height'] / $value['scaled_size']['height'] * $value['data']['y']);
$crop['x2'] = round($value['original_size']['width'] / $value['scaled_size']['width'] * $value['data']['x2']);
$crop['y2'] = round($value['original_size']['height'] / $value['scaled_size']['height'] * $value['data']['y2']);
}
}
// Show and hide different widget fields depends on current display.
// We need this to store actual data about displays in forms cache.
$field =& drupal_array_get_nested_value($form, $image_parents);
_simplecrop_field_widget_switch_display($field, $display);
// Rebuild image widget with a new display.
$form_state['rebuild'] = TRUE;
}