function imagecrop_form_alter in Image javascript crop 6
Same name and namespace in other branches
- 5 imagecrop.module \imagecrop_form_alter()
Implementation of hook_form_alter(). Hook into several existing image modules/fields.
File
- ./
imagecrop.module, line 338 - Provides a javascript toolbox through an imagecache action.
Code
function imagecrop_form_alter(&$form, $form_state, $form_id) {
// No need to do checks on forms, other then node form.
if ($form['#id'] != 'node-form' && $form_id != '_node_images_edit_page' && $form_id != 'user_profile_form' && $form_id != 'taxonomy_form_term') {
return;
}
// Only show cropping link when editing a node.
if ($form['#id'] == 'node-form' && $form['nid']['#value'] == NULL) {
return;
}
$access = user_access('crop images with toolbox');
if (!$access) {
return;
}
// get array of available modules
$hooks = variable_get('imagecrop_modules', array());
// hook into image module
if (isset($form['images']['thumbnail']) && module_exists('image') && in_array('image', $hooks)) {
// do we have presets with javascript_crop ?
if (count(imagecrop_presets_list()) == 0) {
return;
}
// it's anonying we have to make a database call to get the right fid.
$fid = db_result(db_query("SELECT i.fid FROM {image} i LEFT JOIN {files} f on f.fid = i.fid WHERE i.nid=%d AND filepath='%s' AND filename = '_original'", $form['nid']['#value'], $form['images']['_original']['#value']));
$form['croptab'] = array(
'#type' => 'item',
'#value' => imagecrop_linkitem($fid),
'#weight' => -10,
);
}
elseif ($form_id == '_node_images_edit_page' && module_exists('node_images')) {
// do we have presets with javascript_crop ?
if (count(return_presets()) == 0) {
return;
}
$type = $form['#parameters'][2]->type;
if (variable_get('node_images_position_' . $type, 'hide') != 'hide' && in_array('node_images_position_' . $type, $hooks)) {
$form['node_images']['wrapper']['node_images']['imagecrop'] = array(
'#type' => 'hidden',
'#value' => '1',
);
}
}
elseif ($form_id == 'user_profile_form' && isset($form['picture']['current_picture']) && in_array('profile_picture', $hooks)) {
$form['picture']['current_picture']['#value'] .= imagecrop_linkitem($form['_account']['#value']->uid, 'user');
}
elseif ($form_id == 'taxonomy_form_term' && isset($form['taxonomy_image']['current_image']['image']['#value']) && in_array('taxonomy_image', $hooks)) {
$form['taxonomy_image']['current_image']['taxonomy_image_current_image_delete']['#prefix'] .= imagecrop_linkitem($form['tid']['#value'], 'taxonomy_image');
}
}