I wrote a module for Drupal and I have some fields (buttons, image, text).
I want that some fields could be hidden for normal users and open for users when admin let.
This feature is implemented using "Field Permission" module. I don't know how to write PHP code in my module, so can I change permissions using "Field Permission" module?
In your module you can set the #access of those fields depending on roles like:
$roleId = The role id;
// If user doesn't have the role he can't access the field .
if (isset($user->roles[$roleId])) {
// Deny access to the field.
$form['FIELD_NAME']['#access'] = FALSE;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.