Other issues filed on the User Badges queue appear to be problems with other contrib modules, not User Badges

#258403: Badges Not Showing Up on User Profile Until After Role is Re-Applied

In this case I am using "User-Selectable Roles" on registration

with latest 6.x-1.x-dev of User Badges from 2009/10/08

the User Badges do not appear on the user profile for newly registered users until I manually resave the role assignments in the User Badges admin

Comments

johnhanley’s picture

Status: Active » Postponed (maintainer needs more info)

I'm not sure what to make of this. Roles selections made by a user during registration via User-Selectable Roles are added to the user object and saved during account creation using Drupal core functionality. In other words User-Selectable Roles doesn't do anything tricky or proprietary to insert the roles. So the statement that the problem is caused by other contributed modules and not User Badges is purely subjective. That said, I'm willing to accept a patch or fix snippet to make User-Selectable Roles compatible w/ User Badges.

decibel.places’s picture

Well, I think it probably is the User Badges module causing the problem - I was just fishing for a solution/patch whatever here

will update here once it's corrected

thinking about using Rules to save User Badges roles when a role is updated...

decibel.places’s picture

Title: User Badges do not display on newly registered users with User-Selectable Roles until roles are re-saved in User Badges admin » User Badges do not update/add/delete until roles are re-saved in User Badges admin
Project: User-Selectable Roles » User Badges
Version: 6.x-1.5 » 6.x-1.x-dev
Category: support » bug
Status: Postponed (maintainer needs more info) » Active

I added a Rule for every role/badge for add and remove, which update the profile badges properly

I considered writing a custom PHP condition and action so I would only need one pair, but it was easy (if mindless) to clone the Rules

here is example add Rule:

array (
  'rules' => 
  array (
    'rules_1' => 
    array (
      '#type' => 'rule',
      '#set' => 'event_user_update',
      '#label' => 'Add Applicator badge',
      '#active' => 1,
      '#weight' => '0',
      '#categories' => 
      array (
        0 => 'add badge',
      ),
      '#status' => 'custom',
      '#conditions' => 
      array (
        0 => 
        array (
          '#weight' => 0,
          '#info' => 
          array (
            'label' => 'User has role(s)',
            'arguments' => 
            array (
              'user' => 
              array (
                'type' => 'user',
                'label' => 'User',
              ),
            ),
            'module' => 'User',
          ),
          '#name' => 'rules_condition_user_hasrole',
          '#settings' => 
          array (
            'roles' => 
            array (
              0 => 46,
            ),
            'operation' => 'OR',
            '#argument map' => 
            array (
              'user' => 'account',
            ),
          ),
          '#type' => 'condition',
        ),
      ),
      '#actions' => 
      array (
        0 => 
        array (
          '#type' => 'action',
          '#settings' => 
          array (
            'badges' => 
            array (
              1 => 1,
            ),
            '#argument map' => 
            array (
              'user' => 'account',
            ),
          ),
          '#name' => 'rules_core_user_badges_add_badge_action',
          '#info' => 
          array (
            'module' => 'User',
            'arguments' => 
            array (
              'user' => 
              array (
                'label' => 'User',
                'type' => 'user',
              ),
            ),
            'label' => 'Add badge',
            'base' => 'rules_core_action_execute',
            'action_name' => 'user_badges_add_badge_action',
            'configurable' => true,
          ),
          '#weight' => 0,
        ),
      ),
      '#version' => 6003,
    ),
  ),
)

here is the remove Rule for the same role:

array (
  'rules' => 
  array (
    'rules_21' => 
    array (
      '#type' => 'rule',
      '#set' => 'event_user_update',
      '#label' => 'Remove Applicator badge',
      '#active' => 1,
      '#weight' => '0',
      '#categories' => 
      array (
        0 => 'remove badge',
      ),
      '#status' => 'custom',
      '#conditions' => 
      array (
        0 => 
        array (
          '#weight' => 0,
          '#negate' => 1,
          '#type' => 'condition',
          '#settings' => 
          array (
            'roles' => 
            array (
              0 => 46,
            ),
            'operation' => 'OR',
            '#argument map' => 
            array (
              'user' => 'account',
            ),
          ),
          '#info' => 
          array (
            'label' => 'User has role(s)',
            'arguments' => 
            array (
              'user' => 
              array (
                'type' => 'user',
                'label' => 'User',
              ),
            ),
            'module' => 'User',
          ),
          '#name' => 'rules_condition_user_hasrole',
        ),
      ),
      '#actions' => 
      array (
        0 => 
        array (
          '#weight' => 0,
          '#info' => 
          array (
            'module' => 'User',
            'arguments' => 
            array (
              'user' => 
              array (
                'label' => 'User',
                'type' => 'user',
              ),
            ),
            'label' => 'Remove badge',
            'base' => 'rules_core_action_execute',
            'action_name' => 'user_badges_remove_badge_action',
            'configurable' => true,
          ),
          '#name' => 'rules_core_user_badges_remove_badge_action',
          '#settings' => 
          array (
            'badges' => 
            array (
              1 => 1,
            ),
            '#argument map' => 
            array (
              'user' => 'account',
            ),
          ),
          '#type' => 'action',
        ),
      ),
      '#version' => 6003,
    ),
  ),
)
johnhanley’s picture

Awesome--thanks so much for sharing your workaround.

I will leave this thread open for now in case someone identifies a solution to make this unnecessary.

nancydru’s picture

nancydru’s picture

Please try the latest and let me know if this is still happening. Meanwhile, you might want to keep an eye on #782430: Rules integration.

nancydru’s picture

Status: Active » Postponed (maintainer needs more info)
Q2U’s picture

I spent the better part of yesterday trying to get User Badges to work with Role assignments. I started by uninstalling Auto Assign Role and Auto Assign Role was not installed during my experiments. I uninstalled user_badges-6.x-1.6 (2020 Nov 15) and then reinstalled user_badges-6.x-1.6. I then uninstalled user_badges-6.x-1.6 (2010 Nov 15) and installed user_badges-6.x-1.x-dev (2010 Nov 30). I must have cleared the cache 100 times and tried every possible combination of settings. Alas, no matter what I tried User Badges would not appear on the user profile for newly registered users until I manually resaved the role assignments in the User Badges admin > Roles. After 8 hours I gave up and I am now trying to use Rules to add and remove badges when user Roles change. BTW, User Badges is a teriffic mod and it would be a major plus to see User Badges play well with Roles. Thanks.

nancydru’s picture

In addition to the patch above, there is another patch you might be interested in at #782430: Rules integration. They both need review.

Q2U’s picture

Nancy, you wrote: "In addition to the patch above..." but I do not see any patches in this thread, unless I'me being stupid again. Is there a patch here that I'm missing?

Q2U’s picture

Posted by NancyDru on December 6, 2010 at 3:43pm
In addition to the patch above, there is another patch you might be interested in at #782430: Rules integration. They both need review.

I see the #782430: Rules integration patch which NancyDru mentioned, but where is the patch in this thread she referred to?

nancydru’s picture

Q2U’s picture

That is an exported Rule, not a code addition...no? Anyway I tried that and no workee. (

vkareh’s picture

I had a similar problem and the patch in #1092920: New users get Admin-badge assigned fixed it for me. This is for the latest 6.x-1.x-dev.

NeoID’s picture

Even though I have the patch applied from post #14, the problem is still there.

scarr’s picture

I'm also having this issue - subscribing.

nancydru’s picture

In working on getting a D7 version functioning, I discovered that the roles code is really wacky and really not the way things should work, IMHO. So before I go postal and rip most of that code out, let me ask:

A. If role badges always showed last (rightmost) in the list, would that be okay?
B. If A, should role badges be subject to the "Number of badges to display" limit?

nancydru’s picture

nancydru’s picture

marcoBauli’s picture

Patch at #18 seems already committed, but does not solve the problem. Giving a try to the Rules solution at #3 (crossfingers)

shabana.navas’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

Fixed in Version 7. Please upgrade to Version 7.x-3.x.