Badges tab in user profile results in a totally empty page (no html no nothing) if the user has no badges. Web server reports no PHP errors (they're dumped to the error log) and a 200 response result for this page request. Database log contains no errors either, so I'm at a loss and couldn't find the bug myself.

I have several types of badges, one is assigned to certain roles (author/editor roles, but not registered user role), another is assigned by rules trigger for N postings, and others are to be assigned manually by the administration. The intention is that a normal freshly registered user should have no badges at all, so 'registered user' role has no badges. Since the only way to assign badges to specific users is through the tab in their profile, and it would be otherwise pointless to the user since I don't plan to have more types of badges than I have room to display anyway, (One Page Profile module is also used and they show on the main profile page. Turning off one page profile does not change anything, by the way.) access to this tab is restricted by a custom module:

    $items['user/%/badges']['access callback'] = 'user_access';
    $items['user/%/badges']['access arguments'] = array('change badge assignments');

Which I initially blamed for the problem, but turning the custom module off and flushing caches did not fix it, and the badges tab still resulted in a completely empty server response. It does so both for a user with change badge assignments permission and anonymous user.

When assigning the 'registered user' role a badge as well, the problem went away and the badges tab in user profiles is now accessible to users with 'change badge assignments' permission as per my module restriction and does not show for others. However, this is not very acceptable, as now author and admin roles have two role-based badges, which is not what was desired.

Advice on where to stick a debugging statement into would be much appreciated if the problem turns out not to be repeatable.

Comments

Magnus’s picture

The same happens for me. Thought it had something to do about any other modules I have installed so I tried it on a clean install with only Upload module and User Badges installed, but with the same result.

I use private filesystem so I need to use the dev to be able to have an URL instead of uploading images through Drupal.

NancyDru’s picture

Line 525:

    return theme('user_badge_group', $badges);

Needs to be changed to;

    if ($badges) {
      return theme('user_badge_group', $badges);
    }
    else {
      return t('This user is not currently assigned any badges.');
    }
1kenthomas’s picture

Priority: Normal » Major

Any chance anyone can commit this? Or is the module abandoned?

Upping priority, thanks to NancyDru for the fix.

barrya’s picture

As requested by 1kenthomas I've moved my feature request to the bug fix.

Please add a feature where if no badges have been earned, rather than displaying nothing please inform the user viewing that no badges have been earned. This message should be customizable by Admin.

NancyDru’s picture

@ken: I've requested co-maintainer status. If that is granted, then I will commit it.

@barrya: My code gives such a message to the admin when viewing the user's account. If you really want it showing in the content areas, then open another issue for that. However, I can't see a reason for doing such a thing - if they've earned none, then none show.

barrya’s picture

This was why I had opened a seperate issue for the feature in the first place.

Your code fixes the bug, my request was to make the message that was shown to the user customizable by admin - rather than hard coding this, store the message as a system variable that can be updated through an admin screen. The main reason being for this is that even though the module is called user badges, and badges are awarded - on a gaming site for example the badges could be called medals with a message "This user has not earned any medals!". Having a hard coded message refrencing badges may not always be the best solution. Don't forget - for some sites the earning of badges, medals or other rewards may be a key feature, and telling the users on the site that a particular user has not earned anything may be important. It encourages them to take part, and more importantly it shows them that something should/will be displayed when earned. The site users may not all share the same level of intelligence, and by having nothing they may never know that the badges would be a feature and do nothing about it.

I'm not looking to get into an argument here with anyone. I had a seperate issue for this originally, as adding an admin section to control the message is a new feature. Ken suggested I move it to here. If it is decided that this isn't important then so be it - however, I know that the site I am working on *requires* this and it's low on my todo list. This new feature was something I was hoping to submit a patch for when I have completed it, but added it in case someone else had time to do it before me.

NancyDru’s picture

Ah, I see. So there also needs to be an option to show (or not) a "no badges" message. I still think what an admin sees is a separate issue from what end-uers see. The reason for this is that Drupal's issue tracking system isn't good about handling changes that can be done in phases to different parts of code. This thread was originally about fixing a bug in the admin function where you are requesting a new user experience feature. While similar in effect, in my mind as a potential developer, I see them as separate efforts.

BTW, any message that goes through the t() function can be overridden in settings.php (go to the very bottom), so even "hard-coded" messages aren't really. On my current project, they wanted to change "Add a new comment" but I will not hack core, so I used this same capability.

barrya’s picture

My thoughts exactly. I will reopen the other issue.

NancyDru’s picture

Status: Active » Fixed

Committed to 6.x-1.x-dev.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.