function media_gallery_add_images in Media Gallery 7
Same name and namespace in other branches
- 7.2 media_gallery.pages.inc \media_gallery_add_images()
Page callback to add images to a media gallery.
Parameters
$node: The node to which the images should be added.
1 string reference to 'media_gallery_add_images'
- media_gallery_menu in ./
media_gallery.module - Implements hook_menu().
File
- ./
media_gallery.pages.inc, line 287 - Common pages for the Media Gallery module.
Code
function media_gallery_add_images($node) {
// The caller provides a numeric array of file ids that the user selected.
$fids = $_POST['files'];
// Determine which file ids are already included in this gallery.
$items = isset($node->media_gallery_media[LANGUAGE_NONE]) ? $node->media_gallery_media[LANGUAGE_NONE] : array();
foreach ($items as $item) {
$existing_fids[$item['fid']] = TRUE;
}
// Add the newly selected media items to the previous list of items.
foreach ($fids as $fid) {
// Only add a selected item if it isn't already in the gallery.
if (empty($existing_fids[$fid])) {
$file = array();
$file['fid'] = $fid;
$file['title'] = NULL;
$file['data'] = '';
$items[] = $file;
}
}
$node->media_gallery_media[LANGUAGE_NONE] = $items;
node_save($node);
drupal_json_output(array(
'result' => TRUE,
'items' => $items,
));
}