Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Will it be possible to provide support for mulitiple instances of the same flag on a single node view page?
Requirements:
1) Multiple instances of a particular flag on the same page for the same node
3) When one gets flagged/unflagged the other instances shoud also reflect the latest state automatically (through ajax)
Comment | File | Size | Author |
---|---|---|---|
#14 | 843308.flag_.multiple-instances-javascript.patch | 1.02 KB | joachim |
Comments
Comment #1
quicksketchThe first is easily possible through theming, the second is possible but only with some additional work on your part. See:
http://drupal.org/handbook/modules/flag
Placing a Flag Link: http://drupal.org/node/295383
Flag API JavaScript: http://drupal.org/node/336122
Comment #2
chandrabhan CreditAttribution: chandrabhan commentedThank you very much. I achieved the first very easily but for the second one I will look at the material you have referenced.
Comment #4
Garrett Albright CreditAttribution: Garrett Albright commentedReopening because I am facing a similar issue and not sure the best way to go about it.
Here's what I'm looking at (slightly simplified): We have a block which basically displays two Views; Most Recent Items and Most Popular Items. Users can click a "Like/Unlike" button to vote up an item or rescind their vote. A bit of JavaScript makes it so only one View shows in the block at a time; with the click of a tab, one of the Views hides and the other shows up via CSS (no AJAX). The issue is that it is possible, and in some cases quite likely, that an item will appear in both lists, so if someone "Likes" an item in the Most Popular list, then switches to the Most Recent list, we'd like that item to show up as "Liked" in that list as well. What's the best way to go about this?
I've already tinkered with scripting. From what I could see, this would be really easy if I could just have my script pick up the other instance of the "Like" button and then call updateLink() on it with data.newLink. However, since updateLink() is itself inside another function, I'm not able to call it from outside that outer function… that I can tell.
Comment #5
mooffie CreditAttribution: mooffie commentedGarrett, let me know if this code works for you.
Note that we utilize the flag-FLAGNAME-CONTENTID class.
(Whatever, Flag's javascript could certainly be modernized. There's still logic in updateLink() to accommodate "Views Bookmark" (the old module), where there wasn't a wrapper around the links.)
Comment #6
Garrett Albright CreditAttribution: Garrett Albright commentedmooffie, after a tweak or two, that works perfectly. Thanks, man!
Comment #8
nedwardss CreditAttribution: nedwardss commentedThis looks exactly like the solution I need for a similar issue. Unfortunately I'm not quite sure where to put this javascript. Please excuse my ignorance on this.
Thanks.
Comment #9
mooffie CreditAttribution: mooffie commentedI'm quoting from the handbook:
If this doesn't work for you, let us know.
Comment #10
nedwardss CreditAttribution: nedwardss commentedMooffie,
It totally worked for me (with some tweaking); I actually added it with drupal_add_js inline because I only needed it on one node-[CONTENT-TYPE].tpl.php.
Thanks for your help.
Comment #11
walker2238 CreditAttribution: walker2238 commentedSorry to open this but I'm doing the same thing but with D7.
Everything works fine except that the outer div (flag-wrapper) keeps getting appended along with the link. So as a result each time you click the link another flag-wrapper is added.
Here's the JS.
And here is the html to show what happens.
As you can see from the markup above, it seems as if the link and div container are added for each flag action.
Comment #12
joachim CreditAttribution: joachim commentedIs this something we should add to the module JS?
Comment #13
joachim CreditAttribution: joachim commentedLooks like the data var doesn't have data.flagName any more. I can't get this to work.
Comment #14
joachim CreditAttribution: joachim commentedGot it!
We needed to convert flag names to have hyphens instead of underscores. This is working great for me.
Comment #15
joachim CreditAttribution: joachim commentedUntil #1792584: Two flag links displayed on user profile is fixed, this can easily be tested with a user flag ;)
Comment #16
joachim CreditAttribution: joachim commentedPatch needed a reroll. Works for me. Committing, and let's see if we get bug reports in the next alpha release :)
Issue #843308 by mooffie, walker2238, joachim: Added support for multiple instances of the same flag on the same page