Closed (fixed)
Project:
File Entity (fieldable files)
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
14 Aug 2011 at 16:42 UTC
Updated:
22 Oct 2011 at 14:40 UTC
We already have a way to designate custom file types via hook_file_type_info, but no way to let the assign an entity to a new bundle via this, as $file->type is automatically parsed via the mime type. It would be nice to expose a hook for this in file_entity_file_presave:
function file_entity_file_presave($file) {
// Always ensure the filemime property is current.
if (!empty($file->original) || empty($file->filemime)) {
$file->filemime = file_get_mimetype($file->uri);
}
// Always update file type based on filemime.
$file->type = file_get_type($file);
//Allow other modules to alter the file object before presaving it.
drupal_alter('file_entity_presave', $file);
field_attach_presave('file', $file);
}
That way you can now set the custom bundle and allow field_attach_presave to attach the fields from the proper bundle.
If there's interest, I can quickly submit a patch!
Comments
Comment #1
dave reidI'm not sure why you would want to change the file type? Also, you can just use module weights (or module_implements_alter()) to ensure your module's hook_file_presave() runs after file_entity_file_presave().
Comment #2
Jamie Holly commentedOHHHH module_implements_alter. That's a new hook I missed. I'll use that then. Thanks Dave!
Comment #3
Jamie Holly commentedOh and this is a client request. They want only two files - image and generic files. The complaint was if you change the fields or display on say text, then you also got to change then on application (say for a PDF file). I can kind of see what they mean by the extra work. Of course I have no idea why people would constantly change around fields or displays, but you never know!
Comment #4
dave reid