gpt4 book ai didi

Drupal 7 编辑用户页面覆盖

转载 作者:行者123 更新时间:2023-12-02 11:47:20 25 4
gpt4 key购买 nike

我需要覆盖特定用户角色的“user/%user/edit”页面,例如“foo_role”。我已经成功创建了新的用户注册表单,该表单显式选择了用于创建新 foo_role 用户的字段,但是,因为还有其他用户字段不适用于 foo_role,所以该角色的编辑页面不正确。

这是我最好的尝试,但失败了:

function registermodule_form_user_profile_form_alter($form, &$form_state){
global $user;
if(in_array("foo_role", $user->roles)){
unset($form['field_non_foo']);
}
return $form;
}

最佳答案

Alter hooks 使用变量引用来修改内存中的变量内容。因此,您也不需要在 alter hooks 中返回值。

应该看起来像这样:

function registermodule_form_user_profile_form_alter(&$form, &$form_state){
global $user;

if(in_array("foo_role", $user->roles)){
$form['field_non_foo'] = FALSE;
}
}

关于Drupal 7 编辑用户页面覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5018532/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com