简体   繁体   English

在Drupal 6中根据注册字段组合设置新用户的角色

[英]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. 您必须将“ c​​ontent_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.

相关问题 根据用户角色添加附件到WooCommerce新用户注册email - Add attachments based on user role to WooCommerce new user registration email 根据角色重定向Drupal用户 - Redirecting a drupal user based on their role Woocommerce 注册中的附加用户角色选择字段 - Additional user role select field in Woocommerce registration 将新用户与其注册中的角色相关联 Laravel - Relate a new user to a role from their registration Laravel 在woocommerse中注册用户时,会根据国家/地区自动分配用户角色 - Assign user role autometically based on country while user registration in woocommerse 根据 WooCommerce 中的注册 email 设置自定义用户角色 - Set a custom user role based on registration email in WooCommerce 如何在注册过程中根据用户角色将特定的电子邮件域列入白名单 - How to whitelist specific email domains during registration based on user role Wordpress 在注册时以下拉菜单的形式询问用户他们想要的角色 - Wordpress ask user's their desired role as a dropdown menu while registration 在WordPress中设置用户角色:“角色”字符串是否区分大小写? - Setting a user's role in WordPress: Is the 'role' string case sensitive? Drupal 7自定义用户注册表单 - Drupal 7 customize user registration form
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM