function imagecrop_form_alter in Image javascript crop 5
Same name and namespace in other branches
- 6 imagecrop.module \imagecrop_form_alter()
Implementation of hook_form_alter(). Hook into several existing image modules/fields.
File
- ./
imagecrop.module, line 183 - Provides a javascript toolbox through an imagecache action.
Code
function imagecrop_form_alter($form_id, &$form) {
// do we have presets with javascript_crop ?
$exists = imagecrop_action_exists();
// user access
$access = user_access('crop images with toolbox');
// build array with available modules/fields
$modules = variable_get('imagecrop_modules', array());
$fields = variable_get('imagecrop_fields', array());
$hooks = array_merge($modules, $fields);
// hook into imagefield module
if (module_exists('imagefield') && $exists != FALSE && $access) {
$formfield = imagecrop_find_imagefields($form, $fields);
if ($formfield != FALSE) {
$count = count($formfield);
for ($i = 0; $i < $count; $i++) {
$a = 0;
while ($form[$formfield[$i]][$a]['fid']['#value']) {
if (!empty($form[$formfield[$i]][$a]['fid']['#value'])) {
$descr = $form[$formfield[$i]][$a]['description']['#value'] . '<br />' . imagecrop_linkitem($form[$formfield[$i]][$a]['fid']['#value']);
$form[$formfield[$i]][$a]['description']['#value'] = $descr;
}
$a++;
}
}
}
}
// hook into image module
if (module_exists('image') && $exists != FALSE && $access && in_array('image', $hooks) && isset($form['images']['thumbnail'])) {
// it's anonying we have to make a database call to get the right fid.
$fid = db_result(db_query("SELECT fid FROM {files} WHERE nid=%d AND filename = '_original' AND filepath='%s'", $form['nid']['#value'], $form['images']['_original']['#default_value']));
$form['croptab'] = imagecrop_formitem($fid, -10);
}
// hook into node_images module
if (module_exists('node_images') && $form_id == '_node_images_list' && $exists != FALSE && $access) {
$type = $form['#parameters'][1]->type;
if (variable_get('node_images_position_' . $type, 'hide') != 'hide' && in_array('node_images_position_' . $type, $hooks)) {
$form['imagecrop'] = array(
'#type' => 'hidden',
'#value' => '1',
);
}
}
}