Closed (fixed)
Project:
Flag
Version:
5.x-1.0-beta6
Component:
Miscellaneous
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
7 Jul 2008 at 09:21 UTC
Updated:
21 Nov 2008 at 12:54 UTC
On each node that flag is enabled for a nice link can be displayed on that node to flag/unflag the node. However, I'm using a panel to override the default display of a node so this flag/unflag link doesn't appear. What is the php code that displays the flag/unflag link and the nice javascript messages?
Thanks in advance!
Comments
Comment #1
mooffie commentedEDIT: July 10, 2008; ~18:30
The 'dev' version now has a new function, flag_create_link(), that lets you print flag links easily. This function doens't exist 5.x-1.0-beta3. So download this new 'dev' version, and--
In your template (e.g. 'node.tpl.php') do:
Once I get user feedback I'll start a new book page on this subject.
EDIT: July 13, 2008; ~13:05: Note that I renamed the function to 'flag_create_link()'. Previously it had a leading underscore.
Comment #2
neyoung commentedI threw the function at the bottom of the flag.module file. My flag is called favorites so I called the function like this
<?php print _flag_create_link('favorites', $node->nid); ?>This resulted in the following error when I view the node.
Any ideas?
Comment #3
mooffie commentedThat probably means you don't have a $node variable in your template. How do you get at the node?
Comment #4
chadchandler commentedI tried this, and it almost works.
I put the function into template.php, and turned off display in the admin section of flag so it wouldn't appear twice.
Display works when doing this, however when leaving a page after flagging a node you get the following error:
"An HTTP Error 0 occured."
"http://www.yoursite.com/flag/unflag/bookmarks/node/76?destination=taxono... blah blah..
The end of the message varies as to what page you are on.
Note: the node is put in favorites though, just w/ the error message. Ideas?
Comment #5
mooffie commentedProdigy, could you please upgrade your jQuery and see if it makes a difference?
Comment #6
chadchandler commentedNice call Mooffie, I don't know how you do it. Fixed.
Comment #7
chadchandler commentedOnly issue now is anyone who does this may have trouble targeting the .mark and .unmark classes. I'm trying to use the Phark image replacement technique to replace the "mark unmark text" with an image and I had it working before, but now it's back to text only.
Basically, the classes got messed up somehow and I don't know if it was from the flag upgrade I did, or the snippet the involves moving the bookmark around in the template. For clarification, what is the correct way to target a mark, unmark link via CSS?
I'm pretty sure its .flag-"nameofflag" and .unflag="nameofflag" ... no?
Comment #8
mooffie commented(always open new issues for new questions.)
No, it isn't.
First, there's either "flag" or "unflag", depending on what the link does.
Second, there's a fixed "flag-/flagname/" ("fixed" means: it doesn't depend on what the link does, it's always there).
Third, there's a fixed "flag-wrapper" around the link (but you don't have to use this).
I'd start a book page explaining this, but first I need to discuss our CSS classes with Nate, perhaps they aren't final. We're still in beta.
Comment #9
quicksketchTo add on to what moofie said, you can target a particular state of a particular flag by using two classes in you CSS selector:
Unfortunately at the time that I set all these classes, I'd thought that multiple CSS classes to do selection worked in all browsers, but it looks like IE6 doesn't support multiple class selections properly. Bummer. Putting the flag name on the wrapper seems like the best work-around, which I'd definitely support.
Comment #10
neyoung commentedI'm using Panels to access the node. It turns out that when I place the php code in a Custom Content Pane it doesn't have access to the $node variable. Panels uses something called contexts that you could get access to the $node variable, but the node context isn't available in the Custom Content Pane either. I talked to sdboyer, a co-maintainer of Panels, and a new Custom Content Pane will be in the dev version of panels2 tonight that will allow access to the context information. So hopefully in the morning the php code that you provided me will work with the new dev version of panels2 :)
Here are a few resources that sdboyer pointed me to that may be of help to others.
http://groups.drupal.org/node/12843
http://doxy.samboyer.org/panels2/panels_api_plugins_content_types.html
Comment #11
mooffie commentedIMPORTANT:
I've added this flag_create_link() function to the 'dev' version. This will be an official and documented function.
Users who previously pasted this function into their code (neyoung, Prodigy, typehost) should remove it and download the 'dev' version instead. If you don't do this, next time you upgrade the module PHP will bark about a function that's defined twice.
Comment #12
quicksketch@moofie, by Drupal standards, the leading underscore indicates a "private" function, that is, one that shouldn't be called outside the module. If we're sticking with this function, could we take out the leading underscore to indicate it's usage as a public API?
Comment #13
mooffie commentedOK, I've just renamed _flag_create_link() to flag_create_link(). It's just that I wasn't sure this will be our final interface.
A LAST WARNING:
If you continue to use the old _flag_create_link() in your template, you will no longer get a PHP error when you upgrade the module, but your code will fail silently, as our API will change (specifically, $content_type will be removed from theme_flag(), as from other functions). So download the 'dev' (in a few hours) and use flag_create_link() instead.
Comment #14
chadchandler commentedTesting this as I type this. A quick note ... would it be too much to ask to make the "mark/unmark" text optional? I'm having to color my link text the same color as the forground to make it appear invisible.
Comment #15
mooffie commentedThe way to solve this is by theming. Theming is hard right now. Sometime soon it will be easy.
Comment #16
neyoung commentedJust a little update to my issue. I'm cross posting this here for completeness.
http://drupal.org/node/280390#comment-929647
Comment #17
neyoung commentedok, I got this working with panels2!
Since panels2 doesn't give you access to $node I opted to use arg(1) which should be the nid. Add the following code to a 'custom content pane' and add that to your panel.
An alternate solution could be to add the above code to a block and then add that block to your panel. The benefit of using blocks is that you can reuse the block on different pages.
Thanks for everyone who helped with this. I'm very appreciative!
Comment #18
neyoung commentedso I'm guessing I should set the status of this issue to fixed right? This is all new to me.
Comment #19
neyoung commentedComment #20
doc2@drupalfr.org commentedHello there!
I've been looking for this feature for a moment now! So this is currently possible to add a kind of "add to chart" function thanks to the Flags Ops fields in views such as views_bulk_operations.module, or the action_views.module. Which is great! Big thanks to you, dear contributors!
It would be great as well if it was possible to provide the ops as checkboxes, saving much room in views than the redundant "Flag link text".
Is it possible to do that by just putting some javascript instead of the "Flag link text"?
It could be implemented, for example, in views_fastsearch.module result pages. Example of what the combined features would look like: http://www.michael-culture.org/en/search/results.html?q=dance (put your mouse over the "plus" suitcase at the upper-left corner of the checboxes' list)
This could be a way for users to browse the site and flag the content of a first harvest, and then go to their "chart" page to refine their search results.
Comment #21
mooffie commenteddoc2:
Interestingly, mitchell has just spoken of checkboxes. I asked her for her rationale, but didn't get a reply.
Note that this module doesn't support anonymous users (unlike that search page you linked to).
Comment #22
doc2@drupalfr.org commentedYes indeed, mooffie, I've seen it later, but it's tagged as for drupal 6.x... so I wasn't sure. I'll keep an eye on it.
Comment #23
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #24
chadchandler commentedI'm now confused. So this no longer works to manually insert the flag using the latest .dev version for Drupal 5??
Comment #25
mooffie commentedProdigy, it should work (I've just verified this).
What exactly is the code you're using? And where do you put it?
And does the link show if you're _not_ using the "manual" method?
Comment #26
chadchandler commentedI should of been more clear. I apologize. This does manually insert the link to flag the node, but somewhere in the last version the class must of changed for .flag and unflag. My images no longer work, that's all.
Comment #27
mooffie commentedAh, that's very correct. The class names have changed.
But I have very good news for you: you no longer need to bother with CSS tricks. The 'dev' version has a new theming system that makes theming a piece of cake. See 'theme/README.txt' (and 'flag.tpl.php'). I need to start a handbook page introducing this, and also a handbook page with the map of the new CSS names:
#285671: Document theming
But I'm currently bussy working on some other part of this module, so the documentation task has to wait a bit.
Comment #28
mooffie commentedProdigy, I've started the documentation:
Theming guide
If you have problems/questions, please open new issues.
Comment #29
chadchandler commentedThanks Moofie.
The function listed at the top of this page does indeed still work. For anyone converting their class names (if you updated the module) the new method is as follows.
Flag Class
UnFlag Class
Wrapper Class where favorites should be changed to whatever the name of your flag is.
Comment #30
dydecker commentedIs the flag_create_link() function working in 6x-1x.dev version? This code is not returning a link for me
<?php print flag_create_link('bookmarks', $node->nid); ?>Comment #31
dydecker commentedIt does work. Silly me - you must first associate the content type with the flag for it to appear
Comment #32
mooffie commentedI added a "troubleshooting" section to the handbook:
http://drupal.org/node/295383
Comment #33
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #34
Flying Drupalist commentedComment #35
Flying Drupalist commentedsorry, please ignore above.
Comment #36
djpumpkin commentedI'm unable to get the flag link in my advanced user profile pages. The manual fix listed above does not seems to work in 5.x10-beta4
Can anyone please verify this for me?
Thanks
:)
Comment #37
lelizondo commentedis this still working for 5.x-1.0-beta6? because I'm getting:
I don't see the function anywhere in the flag.module.. is there any way to do this with beta6? how?
Thanks
Luis
EDIT: My mistake, I didn't extract all the files..
Comment #38
newdru08 commentedThanks - #17 worked like a charm (in a block).
Any Ideas on how the link may be changed to a button.