Description

The User Badges module allows each user to be assigned 'badges', displayed as a series of iconic images. A common use would be to display the badges along with the user's information within forums, comments, or node postings. These badges can be assigned individually by the administrator or attached to a role so that, for example, all users in the 'admin' role will show the 'Administrator' badge which could display as any graphic.

Any badge can optionally be associated to a URL that links the image to a description page. This URL has token support. If a user has more than one badge, there is also a mechanism that allows administrators to only show the highest level badges.

You can also set a special badge for blocked users and even override their role badges with this one.

User Badges can be used as a way to establish trust (in the same way as eBay's star graphics) or as an incentive for users. They can also be a quick way to identify moderators, administrators, or anyone with a given role.

Limitation

The badge image library is not compatible with the "private" file download method, but the module can still be used; just ignore the Images tab on the badge admin screen.

Dependencies

In order to upload images via the user interface, user badges depends on:
Upload

User Product Badges (sub-module) requires:
ecommerce

Configuration

Once the module is activated, go to Administer >> User management >> Badges (admin/user/user_badges). Here you'll find three tabbed sections for User Badges.

  • List - Lists all current badges and allows you to edit them.
  • Add - Add a new badge.
  • Images - The badge image library. If you already have images available, you can ignore this, but if you need a way to upload images for badges, this is the place.
  • Roles - Here you can associate a badge with a given role so that all users with that role will display the selected badge.
  • Settings - where you can set the global settings for the module.
  • Products - This tab is provided by the module User Product Badges. It allows you to associate badges with products for the ecommerce module.

Permissions

The module provides two permissions:

  • Users with the 'manage badges' access permission will have access to the administration pages for the module.
  • Users with the 'change badge assignments' access permission will be shown a 'Badges' tab when visiting user profiles. This is the place to manually assign badges to users.

Display badges

To display user badges in your theme use:

  if (module_exists('user_badges')) {
    print user_badges_for_uid($uid);
  }

Note: $uid means 'a user id' here, not the literal use of $uid. Most people will use the uid of the node ($node->uid) or comment ($comment->uid) author.

In Drupal (and theming), $node is a PHP object that represents the node, and $comment represents the comment. They are not always both available in every template file, so check the comments at the top of the file to see what is available. You may have access to other uids (user ids), and in these cases you can replace $uid with that value.

Comments

bgregory’s picture

In what folder/file do I put the code:

  if (module_exists('user_badges')) {
    print user_badges_for_uid($uid);
  }

Sorry, but I am new to drupal.

Thanks

NancyDru’s picture

I'm going to guess that you want that in a theme template, probably node.tpl.php.

bgregory’s picture

Hi, thanks for the reply. It looks like you are right with the node.tpl.php even from my limited knowledge, although I put the code in and again it did not work.

My theme is Acquia Marina which runs on Fusion Core. AM is the main theme but the node.tpl.php file is in Fusion. Does this mean anything and would it make a difference? Both are enabled just to let you know.

Also I have just read the note below the code for all that it means to me. Does it mean that I have to amend the code? If so in what way? I know very little to nothing about coding so all help and instructions would be much appreciated.

Thanks

NancyDru’s picture

My standard practice is to copy any templates I plan to modify from the parent theme to the sub-theme, and modify it there. I don't know if that is required or not.

bgregory’s picture

Hi, I have tried that and still nothing. I think I am just going to give up now and find something else.

NancyDru’s picture

You're likely to get better help in the module's issue queue.

aharown07’s picture

I have not found this documented anywhere, but in my Drupal 7 themes, the code has to be added to the appropriate template as follows... (example is comments template, which is typically comment.tpl.php. If stored in your theme folder, this file would normally override any other templates the Comments module might be trying to use... there would be some differences for nodes, and profile. Still working on Profile.)

<?php if (module_exists('user_badges')): ?>
    <?php print user_badges_for_uid($comment->uid); ?>
<?php endif; ?>