excuseme if this question can (seem to) be stupid, but I don't figure how to solve...

Shortly, my custom module:

  • exposes a node type
  • exposes an entity type
  • attach to that node a field containing a set of these entities (by using entity_reference)

I would like to customise how those entities are visualised in the node view page: I would like to show more info instead of just the entity label.

I read something about hook_field_formatter_info(), that seems to be the best solution, but my debugger suggests that is not invoked (neither after a cache clear)... on the other I can't find any info about how to explain this to hook_theme().

The ideal behaviour should be to tell to Drupal:

  • use a specific template file to render all fields belonging to a given field instance
  • allow a theme to override that representation in a new template file

Do you have a snippet of code or a web resource explaining how to instruct my module to do this?

Thank you

1 Answer 1


hook_field_formatter_info() hook lets Drupal know about the new display denfinition and field settings, you will see your display type under Manage display settings of your content type. However the actual format of the field is returned with help of hook_field_formatter_view.

Example Code

  • Thank you for replying... but it seems that your solution is to create a new formatter for an existing (defined elsewhere) field... instead I would like that my module declare the entity (by hook_schema and hook_entity_info), declare the field (inside hook_install), and declare (I don't know where) how that entity, shown as a field, has to be rendered using a .tpl.php file. Am I in wrong, or your example fits better for already existing fields? Thank you. Commented Oct 21, 2016 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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