Drupal, user profiles: adding fields *only* editable by administrators

邮差的信 提交于 2019-12-11 10:07:50

问题


I would like to add a field to user profiles that only administrator can use and change for each user.

In other words, it should be visible in users profiles but not editable by users (only by administrators).

I cannot do it with drupal permissions, right ?

thanks


回答1:


With hook_form_alter you can set a permission on form fields. That way only users with the permission can edit it.

Example:

$form['example']['#access'] = user_access('permission');



回答2:


This is nearly the same question as Drupal 7 fields - only editable by specific roles - how?. Use the Field Permissions module.



来源:https://stackoverflow.com/questions/3268161/drupal-user-profiles-adding-fields-only-editable-by-administrators

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!