2

I have a content type which has a full content and teaser display. It has a number of fields, and one of the fields on it is an Entity Reference field which references users (called field_registered_users with unlimited values allowed).

If a user views the node and they aren't referenced within the field then I want to hide certain fields on the node.

How do I do this? Should I do it in the template file or through a custom module? I also want to display a block on the page instead of the fields if this is the case.

1

business logic never in tpl.

You could use hook_node_view($node, $view_mode, $langcode).

In my opinion the cleanest and the most drupal way would be to create a custom formatter (mymodule_field_formatter_info) in which you should pass the returned value (1 or 0) of your business logic to the #access property of the field

Regards.

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.