Permissions Drupal自定义表单字段权限
是否可以根据用户角色设置限制对自定义表单(hook_form)字段的访问。(即)字段权限模块为cck提供了这种灵活性,但不适用于自定义表单字段。我不知道有哪种模块可用于此,但您可以这样做Permissions Drupal自定义表单字段权限,permissions,drupal-7,hook-form,Permissions,Drupal 7,Hook Form,是否可以根据用户角色设置限制对自定义表单(hook_form)字段的访问。(即)字段权限模块为cck提供了这种灵活性,但不适用于自定义表单字段。我不知道有哪种模块可用于此,但您可以这样做 function custom_form(){ //obtained logged in user and his roles global $user; $current_role = $user->roles; //this form field is static $form = array()
function custom_form(){
//obtained logged in user and his roles
global $user;
$current_role = $user->roles;
//this form field is static
$form = array();
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('name'),
);
//the below form fields are based on the current_role of the user
if(in_array('test1', $current_role)){
$form['conditional'] = array(
'#type' => 'textfield',
'#title' => t('test1'),
);
}
if(in_array('test2', $current_role)){
$form['conditional'] = array(
'#type' => 'textfield',
'#title' => t('test2'),
);
}
return $form;
}
我不知道这是否正是你需要的功能。
在这里,如果用户有角色test1,它将显示文本字段“test1”;如果用户有角色test2,它将显示文本字段“test2”
希望这有帮助