When working on the Media sprint in Barcelona, we figured out It is not possible to define your own type of file. It always gets mapped through the file_entity_file_presave().
So if you are doing the following:
$file = file_load($fid);
$file->type = 'my_fuzzy_type';
file_save($file);
The presave function doesn't respect the type I set. For the upcoming custom file types this should be changed by checking if the type is set.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | do-not-overwirte-type-1637382-2.patch | 537 bytes | michaelmol |
| #1 | do-not-overwirte-type-1637382-1.patch | 538 bytes | michaelmol |
Comments
Comment #1
michaelmol commentedPatch attached
Comment #2
michaelmol commentedMy bad, new patch.
Comment #3
slashrsm commented#1292382: Make it possible to create any number of custom File Types will change the way how types are determined for files. Maybe this should be included in that issue?
Comment #4
mauritsl commentedDid you mean file_type_determine() ?
The hook_file_type() is great, but file_type_determine() shows exactly the problem. There can be more than 1 filetype matching the file. We should be able to change that filetype (with file_save()).
This is required for the multi-step upload (#1553114: Adding files should be a multi-step process).
When the file is uploaded it will be automatically registered as a file object by Drupal. There an assumption is already made on the filetype. Thus if you have the bundles "photo" and "logo", it will probably be saved as a "photo". The second step in multi-step upload is asking the correct filetype to the user. The file can then be converted to a "logo" if the user says it's a logo.
This workflow is a bit dirty. Maybe new files should be saved with an "undefined" type first, before setting the correct type. Anyway.. The new hook is not a complete solution for this. This bug is still valid.
Comment #5
slashrsm commentedI do not state that file_type_determine() does the job. It is just a suggestion. My point in #3 was, that patches in #1292382: Make it possible to create any number of custom File Types already totally change the code, which is discussed in this issue. That's why I think we should mark this as duplicate and keep this debate going on in that issue.
You have a good point in #4, but we should discuss things in one place.
Comment #5.0
slashrsm commentedrevisted description