繁体   English   中英

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

[英]Setting the new user's role based on registration field combo in Drupal 6

我正在编写一个Drupal 6模块,其中的任务是根据“内容配置文件”字段在注册表单上显示的组合中的选择,向在我的网站上注册的用户分配特定角色。 (自动分配角色模块不适用于我,因为我必须根据角色选择使用条件字段,并且无法同时完成这两项工作。)

在我的模块中,我实现了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:如果您有任何建议如何在不进行远程调试的情况下很好地记录消息,请将其包括在分析工具中:-)

要为给定的用户加载内容概要文件,可以使用以下代码:

$profile = content_profile_load( 'content_profile_type', $uid );

您必须将“ c​​ontent_profile_type”替换为内容配置文件的内容类型的机器名称。

关于您关于如何在不进行远程调试的情况下很好地记录消息的问题,我建议您使用devel模块提供的dpm()函数。 有关dpm()函数的更多信息,您可以访问http://drupal.org/node/174575

因此,在加载内容配置文件后,您可以像这样调用dpm():

dpm($profile);

它将显示有关Drupal主题的消息区域中$ profile变量中包含的内容的信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM