I've added a field to comments to allow users to upload files. I want users to be able to upload different types of files, but if it's an image then show a thumbnail. Can this be done while just using 1 field?
All you need is writing your own display formatter for file fields. have a look at field_example module to see where you should start:
first define your display formatter using hook_field_formatter_info, here with
field types you can specify that this display formatter is for file fields.
then all you need is implementing hook_field_formatter_view, here you should output different
$element based on
after developing this tiny module, go to
comment display setting in your content type page and select your new display formatter to rendering that field.
From field example module:
I think your best candidate for this job is
hook_field_prepare_view(). You can alter field's values just before they get to be displayed. Take a look at the docs here.
I found y'all's answers really helpful, but for my purposes, the custom_formatters module seemed to work really well.