Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
It seems that when i output field in node template file like:
$myfield = field_get_items('node', $node, 'field_myfield');
$myfield = $myfield[0]['value'];
print $myfield;
That it overrides field permission settings and outputs field for all users.
Is this by design ?
If so, how i can include field permission check at this level ?
Comments
Comment #1
fossle CreditAttribution: fossle commentedI am having the same issue. Did you find a solution for this?
Comment #2
mariacha1 CreditAttribution: mariacha1 at ThinkShout commentedAs mentioned in the first comment here:
https://api.drupal.org/comment/23698#comment-23698
field_get_items() bypasses permissions. If you want to get the access level, you can follow up with a check to field_view_value(). Here's how this would work with, say, the Body field of a node:
The value of $output is:
So you'd want to check the #access of the field before outputting it.