Active
Project:
Image Browser
Version:
6.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
8 Aug 2010 at 12:33 UTC
Updated:
8 Aug 2010 at 15:17 UTC
A nice, and very simple, addition would be to add a drupal_alter to the process of uploading an image. That would allow other modules to do something with the file. In my case, I am using OG and I want to create a node for the image and make sure it has been assigned to the right group so that I can limit the available images by group. But there are lots of other possibilities from such a change.
It would only take one line, the function would end up looking like:
function imagebrowser_upload_submit($form_id, $form_values) {
// If image module is present, we store the image file as an image node.
if (module_exists('image')) {
....
}
// If no image module present, the image is stored as a permanent file.
else {
// Make file permanent and move to images direction
$file = file_save_upload('upload', array(), file_directory_path().'/images'); // Save temp file.
file_set_status($file, FILE_STATUS_PERMANENT);
// NEW LINE: Let other modules do something with this file, like store it in a node.
drupal_alter('imagebrowser_upload', $file);
$fail = (!$file);
}
....
Comments
Comment #1
karens commentedIn case you're wondering why I don't use the image module to create nodes, it has a ton of overhead I don't want, I just want a simple node with an imagefield. Using imagefield, I can take advantage of access control, add other information to the image, place it in a gallery, etc.
In case anyone wants to see how this would work, using the above hook, I can add the following code to mymodule to create the imagefield nodes when the images are uploaded and assign them to the right OG group. This is not fully debugged code, it is just an example. After that, I can alter my imagebrowser view to only include images from the current group instead of showing all images on the site.
Comment #2
karens commentedWell one more update, in case anyone else is trying to use the above code to update a group. The group context can't be discovered automatically at that point in time, I have to set it earlier, in a $_SESSION variable and then retrieve it when I save the node, but the method still works great -- it allows me to create nodes for these files.