Download file field dependent on user role vs role field values I have a type downloadable_item which has a field field_roles_allowed that is based on the Role Field Module.

My goal is to have a field_download of file type that will show the file for download if the user in a role selected in the field_roles_allowed and a message that they need to request access otherwise.

I am attempting to add a formatter for the file field type using the Custom Formatters Module. I found this tutorial on how to use the Custom Formatters module, however, they use the "HTML + Tokens" option. I will need to use the PHP option to be able to output either the download button or a message depending on whether the user is in a role in the field_roles_allowed.

I cannot figure out how to get the roles that are allowed, download file information, and current user's roles for comparison.

My question is really "How do I do these things that I cannot figure out?", but if someone believes I am going about this totally in the wrong way... I am open to another way.



EDIT: I solved my own problem below, but not really in a preferable way. How could this be done without writing PHP logic in field?
After some digging... I found that I am able to get field information like...

$variables["#object"]-&gt;field_roles_allowed["und"]; //array containing id's of roles allowed
$variables["#object"]-&gt;field_download["und"]; //array containing information about the file


and that I can get the current user's roles like...

global $user;
$user-&gt;roles; //array containing current user's roles


Then I can compare the field roles allowed with the current user's roles and determine what to output from there.

Still not very happy with this, I would prefer something where I don't have to write PHP logic in a field.