I've created a custom field formatter which works correctly. My problem is that I want to differentiate its output depending on whether it's being used in a default
or teaser
view mode.
The hook_field_formatter_view doesn't seem to provide this.
One way I can solve this is by providing a setting on that formatter (hook_field_formatter_settings_form) with possible values default
and teaser
. I'd then have to go to the teaser view mode of all content types and configure this setting on all uses of that formatter. I'd then be able to get the setting using $display['settings']
. This would work but it's a bad solution since it would be replicating data that is already there and it also requires administrative work.
Is there a cleaner solution to this?
$instance['display']
is keyed by view mode, so for that alone it's necessary. My understanding of the Drupal way here is that you provide the general purpose tools (just like a module typically provides permissions, but not a new role - leaving it to the site builder to aggregate perms into roles appropriate for their particular needs). Every time I create a new view mode I want to have complete power to make it do exactly what I want. My 2 pennies...