I have a video field that should be visible only to authenticated users on one content type (bundle), but unrestricted on another content type.
What's a clean way to hide this field on one content type only, for anonymous users?
Notes:
I have the module field permissions installed, but it doesn't support per bundle field permissions.
I'm using Display Suite, so I'd rather not use a custom template unless that's the cleanest way to handle this one field.
I could create a new view mode that hides this field and and use HOOK_entity_view_mode_alter to switch to that view mode for anonymous users, but there are quite a lot fields to display so having 2 big view modes that are 95% the same seems kind of silly.
Edit: This is the code I used based on @wolverine's answer below:
function HOOK_utility_field_access($op, $field, $entity_type, $entity, $account) {
//Check video field only when attached to 'lesson'.
if ($field['field_name'] == 'field_video' && $entity_type == 'node' && $op == 'view' && $entity->type == 'lesson') {
//Grant access only if user is logged in.
if ($account->uid > 0) {
return TRUE;
}
return FALSE;
}
}