0

I'm developing a module that exposes a node type (by the usual hook_node_info() and hook_install()) and a set of custom fields.

I would like to programmatically define what/how those fields have to be shown in the node views (at least "full"). For example: the field XYZ should be hidden in the "full" mode, and the field ABC should have the lable inline (I'm able to do this by UI, but I would like to define it programmatically).

In any case my need is to exactly modify the view mode (not to always hide a field), in order to allow users to modify the default visualisation way after installation, if necessary.

I can't figure what hook I have to implement, or what code I have to write in the hook_install.

Thank you for your help

1 Answer 1

0

I want to share the solution I found, in order to help future readers.

In Drupal 7 the concept of "formatter" helpt to control the output of a field. For example this tutorial allow you to programmatically define a custom formatter for a given field.

Then by UI site admins (by admin/structure/types/manage/<nodetype-name>/display) are able to chose that formatter (or others) for any specific field.

If you want to declare a default formatter for a field, the best way seems to be while the install phase of the module. In that moment (At least in my case and in all tutorial I found on the Internet) you use a field_create_instance method to add a specific instance of a given field. According to the official documentation, you can also add the display options that exactly allow you to define the formatter to be used for a specific display (or the formatters if want to declare for more than one display).

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.