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.

Comments

michaelmol’s picture

StatusFileSize
new538 bytes

Patch attached

michaelmol’s picture

StatusFileSize
new537 bytes

My bad, new patch.

slashrsm’s picture

#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?

mauritsl’s picture

Did 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.

slashrsm’s picture

Status: Needs review » Closed (duplicate)

I 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.

slashrsm’s picture

Issue summary: View changes

revisted description