[英]Setting the new user's role based on registration field combo in Drupal 6
I'm writing a Drupal 6 module where my task is assingning a specific role to users who register on my site based on a selection from a combo put on the registration form by Content Profile field. 我正在编写一个Drupal 6模块,其中的任务是根据“内容配置文件”字段在注册表单上显示的组合中的选择,向在我的网站上注册的用户分配特定角色。 (Autoassign Role module didn't work for me because I have to use conditional fields based on the role selection and I could not get these two work togedher.)
(自动分配角色模块不适用于我,因为我必须根据角色选择使用条件字段,并且无法同时完成这两项工作。)
in my module I implemented hook_user(), but I don't know how to make the decision based on the field value because I cannot see the profile fields' values in my &edit or &account objects. 在我的模块中,我实现了hook_user(),但是我不知道如何根据字段值做出决定,因为我无法在&edit或&account对象中看到配置文件字段的值。
/**
* Implementation of hook_user().
*/
function mymodule_user($op, &$edit, &$account, $category = NULL) {
switch ($op) {
case 'isnert':
$rolenames = user_roles();
// 6 : magical role
//profile_load_profile($account); // tried with and without this
var_dump($account);
//var_dump($edit);
if(true) { // the decision should be made here based on the combo!
$edit['roles'] += array('6' => $rolenames[6]);
}
break;
ps: if you have any suggestions how to log messages nicely without remote debugging please include it into your anser :-) ps:如果您有任何建议如何在不进行远程调试的情况下很好地记录消息,请将其包括在分析工具中:-)
To load up the content profile for a given user you can use the following code: 要为给定的用户加载内容概要文件,可以使用以下代码:
$profile = content_profile_load( 'content_profile_type', $uid );
You must replace 'content_profile_type' with the machine name of the content type that is your content profile. 您必须将“ content_profile_type”替换为内容配置文件的内容类型的机器名称。
Regarding your question about logging messages nicely without remote debugging goes, I would suggest using the dpm() function provided by the devel module. 关于您关于如何在不进行远程调试的情况下很好地记录消息的问题,我建议您使用devel模块提供的dpm()函数。 For more info about the dpm() function you can visit http://drupal.org/node/174575
有关dpm()函数的更多信息,您可以访问http://drupal.org/node/174575
So, after loading up the content profile you could call dpm() like so: 因此,在加载内容配置文件后,您可以像这样调用dpm():
dpm($profile);
Which would show you information about what is contained in the $profile variable in the messages area of your Drupal theme. 它将显示有关Drupal主题的消息区域中$ profile变量中包含的内容的信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.