function imagefield_js in ImageField 5.2
Menu-callback for JavaScript-based uploads.
1 string reference to 'imagefield_js'
- imagefield_menu in ./
imagefield.module - Implementation of hook_menu().
File
- ./
imagefield.module, line 1129 - Defines an image field type. imagefield uses content.module to store the fid, and the drupal files table to store the actual file data.
Code
function imagefield_js() {
// Parse fieldname from submit button.
$matches = array();
foreach (array_keys($_POST) as $key) {
if (preg_match('/cck_imagefield_(.*)_op/', $key, $matches)) {
break;
}
}
$fieldname = $matches[1];
$node = (object) $_POST;
// Load field data.
$field = content_fields($fieldname, $node->type);
// Load fid's stored by content.module
$items = array();
$values = content_field('load', $node, $field, $items, false, false);
$items = $values[$fieldname];
// Load additional field data
imagefield_field('load', $node, $field, $items, false, false);
// Handle uploads and validation.
_imagefield_widget_prepare_form_values($node, $field, $items);
_imagefield_widget_validate($node, $field, $items);
if (is_array($node->{$fieldname}) && count($node->{$fieldname}) > 0) {
foreach ($node->{$fieldname} as $key => $image) {
// Set the alt and title from POST
$items[$key]['alt'] = $image['alt'];
$items[$key]['title'] = $image['title'];
$items[$key]['flags']['delete'] = $image['flags']['delete'];
}
}
// Get our new form baby, yeah tiger, get em!
$form = _imagefield_widget_form($node, $field, $items);
foreach (module_implements('form_alter') as $module) {
$function = $module . '_form_alter';
$function('imagefield_js', $form);
}
$form = form_builder('imagefield_js', $form);
$output = theme('status_messages', 'error') . drupal_render($form);
// We send the updated file attachments form.
$GLOBALS['devel_shutdown'] = false;
echo drupal_to_js(array(
'status' => true,
'data' => $output,
));
exit;
}