function taxonomy_image_attach_form_alter in Taxonomy Image 5
Same name and namespace in other branches
- 6 contributed/taxonomy_image_attach/taxonomy_image_attach.module \taxonomy_image_attach_form_alter()
Add an image selector to the taxonomy_image fieldset alongside the upload field.
File
- contributed/
taxonomy_image_attach/ taxonomy_image_attach.module, line 73 - Add functionality to terms similar to the image_attach.module. Allow a term editor to choose from EXISTING images rather than upload new ones all the time. Currently this uses image.module handling of image nodes to index available images.
Code
function taxonomy_image_attach_form_alter($form_id, &$form) {
switch ($form_id) {
case 'taxonomy_form_term':
$current_image = taxonomy_image_get_object($form['tid']['#value']);
$current_filepath = $current_image->path;
// Reverse-lookup to figure what this attached image is, if any.
$file = db_fetch_object(db_query("SELECT * FROM {files} WHERE filepath = '%s'", $current_filepath));
// If none, no problem.
$all_images = taxonomy_image_attach_get_image_nodes();
$form['taxonomy_image']['image_attach']['iid'] = array(
'#type' => 'select',
'#title' => t('Use existing image'),
'#options' => $all_images,
'#default_value' => $file->nid,
'#description' => t("Choose from existing image nodes."),
'#prefix' => t('<strong>or:</strong>'),
);
// TODO: Ajax to display the one you just chose?
$sizes = image_get_sizes();
$size_options = array();
foreach ($sizes as $size => $size_def) {
$size_options[$size] = $size;
}
$form['taxonomy_image']['image_attach']['image_size'] = array(
'#type' => 'select',
'#title' => t('Preset size from existing image'),
'#default_value' => $file->filename ? $file->filename : variable_get('taxonomy_image_attach_default_size', 'thumbnail'),
'#options' => $size_options,
'#description' => t("Any resizing preferences set in the taxonomy_image admin may over-ride this size choice."),
);
if (!variable_get('taxonomy_image_attach_enable_size', FALSE)) {
// Actually, scratch that selector, if you're not allowed to use it. Just set a value.
$form['taxonomy_image']['image_attach']['image_size']['#type'] = 'value';
$form['taxonomy_image']['image_attach']['image_size']['#value'] = variable_get('taxonomy_image_attach_default_size', 'thumbnail');
}
break;
}
return $form;
}