1

I created a field with the field type "file" I now have to convert this to "image" field type. The field has already content so I cannot not delete and recreate a new one. How can I do this programatically using the hook_update in my module?

1

Hook update performs an update on a node, it wont be too useful in your case. When you create a field it creates a table in the DB with appropriate datatypes. You cannot just change the datatype of a field without going down the line and changing all the details, including the data in most cases. which trust me is a huge pain in the ass.

I've had to do this before but what i ended up doing was creating new field with the datatype I wanted, then used View Bulk operations Execute arbitrary PHP script and ran custom php to get the FID from all the File and then add it to the new field. I think there was a user reference for each file as well, so the fidelity is there to transfer your data between fields. Then delete the old field

Worst case scenario, find ways of limiting what types of files(image only) your file upload field can upload.

  • I thought this would be more easy, I may reconsider the changing of the file type :) – abelass Jun 10 '16 at 8:28
0

I did the "inverse" to change from iamge to file to use the multiupload widget on images gallery without loose any pictures.

UPDATE `my_databse`.`field_config` SET `type`='file' WHERE `id`='7';

id=7 is corresponding to he field I wanted to change.

my field_config table

Hope it could help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.