If I understand correctly, hook_field_prepare_view should be called each time, when some field value is displayed. But when I visit some node page, that contains some fields, my hook_field_prepare_view is not called. I have simple hook implementation as follows:

function mymodule_field_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items) {
watchdog('mymodule', 'field');

I have no record 'field' in log messages, so I think my function is not called. I flushed caches several times. Could anybody help, where can be problem?

  • 4
    Field hooks are mostly only invoked for the module that implements the field. If you're trying to prepare the view for a field you've defined yourself in hook_field_info(), then this would be the correct hook to use. If you're trying to alter the view of a field defined by another module, I think you'll need to find a different approach – Clive Jul 4 '13 at 11:25

As documentation says:

This hook is invoked before the field values are handed to formatters for display

It will not be called when content is served from cache - as values are not handed anywhere, it's just output taken from cache table (or other cache bin) and sent to display.

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.