开发者

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

开发者 https://www.devze.com 2023-03-25 16:58 出处:网络
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. (Au

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. (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.

/**
 * 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 :-)


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.

Regarding your question about logging messages nicely without remote debugging goes, I would suggest using the dpm() function provided by the devel module. For more info about the dpm() function you can visit http://drupal.org/node/174575

So, after loading up the content profile you could call dpm() like so:

dpm($profile);

Which would show you information about what is contained in the $profile variable in the messages area of your Drupal theme.

0

精彩评论

暂无评论...
验证码 换一张
取 消