[英]How to set custom permission for buttons or fields in Drupal?
我为Drupal编写了一个模块,并且有一些字段(按钮,图像,文本)。
我希望某些字段对于普通用户可以隐藏,并在管理员允许时为用户打开。
使用“字段权限”模块可实现此功能。 我不知道如何在模块中编写PHP代码,因此可以使用“字段权限”模块更改权限吗?
在模块中,您可以根据以下角色设置这些字段的#access权限:
$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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.