Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I've got two file types - the default Document and a second custom file type, Vacancy Application. They both are tied to PDF and Word documents. I would like to use the Document file type on one particular file field and Vacancy Application on another file field. I can't see any current way of specifying which file type those file fields use. As it stands, having just created the custom Vacancy Application file type, it seems to be overriding the Document file type on all pdf/word document file uploads.
Is there any way I can specify which file field uses which file type?
Cheers
welly
Comments
Comment #1
welly CreditAttribution: welly commentedI'm just looking at the file_entity_file_presave function and it looks like this is where the file type is specified so perhaps I can create a helper module that will implement the hook_file_presave function and select the file type there. I'll give it a go.
Comment #2
Pierre.G CreditAttribution: Pierre.G commentedI couldn't figure out how to get the field_name in
hook_file_presave
function. I usedhook_field_attach_presave
function instead and force file->type for my filefield here.It works but I'm not really sure if it is the best way to do it.
I would prefer doing it when the file is saved.
Any feedbacks ?
Comment #3
cobenashI am facing the same issue. Any feedbacks ?
@Pierre Did your code still work perfectly ?