1

是否可以根据用户角色设置限制对自定义表单(hook_form)字段的访问。(即)字段权限模块为 cck 提供了灵活性,但不适用于自定义表单字段。

4

1 回答 1

2

好吧,我不知道任何模块,但你可以做到这一点。

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。

希望这可以帮助。

于 2014-01-27T17:48:25.507 回答