Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
I have create a view of badges and set anchor name references for each badge. In this way, if I manually type the view url with the named tag, it automatically jumps to that spot on the page.
For example:
http://mysite.com/badges#fan-badge
This work great when I type in manually, but I'm trying to set the link on the badge image, so if someone views a user profile with that badge and clicks on it, it should take him to the above link. However, it really takes him here (and I get a page not found error).
http://mysite.com/badges%2523fan-badge
Comments
Comment #1
NancyDruThat looks like it might be a double-encoding error. Can you explain in greater detail, please, so that I can better understand the situation?
Comment #2
benlotter CreditAttribution: benlotter commentedHere is greater detail including exact steps to reproduce.
Go to /admin/user/user_badges/list. Then click Edit next to one of the badges (ex /admin/user/user_badges/edit/1). In the Description URL enter "badges#fan-badge". Then click Submit.
Finally view your badge and click on it's link. It will take you to this URL "/badges%2523fan-badge" which is not the desired behavior. The desired behavior is to take you to "/badges#fan-badge".
I have also tried entering (in place of the "#") the url encoding for it. But that does not work either.
FYI, my workaround was to create a separate node for each page to view. But what I really want is a list (view) of all the badges but to jump to the anchor name of the badge you just clicked on.
Comment #3
NancyDruAt the end of function theme_user_badge, replace the
return l(...
with:This works for me and will be in the next commit unless you say it doesn't.
Comment #4
benlotter CreditAttribution: benlotter commentedI may have done something wrong because now all the badges simply link to the home page. Here is the entire function after I attempted to edit it per your instructions. When I changed it back everything started working again (including the bug, of course).
UPDATE: I did look at the code and noticed you had change $badge->href to $href. Anyway, I made a couple of attempts to adapt your code and came up with this. The following works (note, my changes in bold below) on my installation and fixes the # bug. :) Thank you very much.
Okay, so I couldn't get it to highlight in bold but the change I made was here: $pieces = parse_url($badge->href);
Comment #5
NancyDruSorry, my suggestion was based on 6.x-1.6. There are a ton of fixes above 1.5; I highly suggest updating. The new Token support sets $href.
Comment #6
sophievn107 CreditAttribution: sophievn107 commentedJust curious. badges#fan-badge is a new page on your site? where do u define and create this?
Comment #7
benlotter CreditAttribution: benlotter commentedI have a badge content type which include the Title: Name, Body: Description and a CCK imagefield for the badge image. Then I created a view with a page output of badges. Also it outputs the . I do this so that when someone clicks on any badges they see all the badges but the page is scrolled to the one they clicked on. But then they will see all badges so they will be curious how to earn those as well.
Comment #8
NancyDru@benlotter: That sounds like an awesome idea! And it sounds like it might be a good highlight site for the project page.
Comment #9
benlotter CreditAttribution: benlotter commentedI love the new token support in 1.6. :) Unfortunately it broke the named tag (#) functionality that I had from #3 and #4. I tried for 1/2 hour to integrate the token code with the $pieces code with no success. In the end, I had to yank the token code in favor of the $pieces code since that is the functionality I desire. Here's what my full theme_user_badge() looks like now.
Comment #10
benlotter CreditAttribution: benlotter commented@NancyDru Thanks for all your help. Once I can get everything working and get the site out of BETA, I can submit it as an example. Sorry, I hate showing my unfinished work off except to those who have been warned that I'm constantly breaking it to make it better.
Comment #11
sophievn107 CreditAttribution: sophievn107 commentedHi, for my site, I would like to link the badge image to the new page, which show that particular badge's image, details as well as the date that the user earned the badge (not redirect to the badge list page), so basically different badges will link to different pages (eg. user/232/badges/agagtqtq111 or something like that.
Any thoughts? Please help.
Comment #12
benlotter CreditAttribution: benlotter commentedHave you tried the new token support in 1.6? You should be able to link to the user's profile page where you can see the badges if they are displayed. Beyond that, you might need to create a view which accepts the user-id as a parameter to accomplish your goal.
Comment #13
NancyDru@sophievn107: At least the current -dev version does most of that already; I can't recall if that was in 1.6. Every badge has a setting for "Description URL" which allows you to create a node and fill this in with "node/1234" (where 1234 is the correct node ID). That node can describe the badge. As benlotter suggested the "Default badge link URL" could contain
user/[uid]/badges
.Unfortunately, we don't currently keep track of the date it was earned. And with the issues requesting multiple badge earning, which date would you show, the first or the most recent? However, I would appreciate it if you would open a new feature request for this.
Comment #14
NancyDruI have removed drupal_get_destination() (apparently it is not needed any way) from the theme_user_badge function. You should be able to revert to the standard code, complete with token support.