Come together with the global Drupal community in Rotterdam, 28 Sept – 1 Oct 2026. Sessions, contribution, connection, and Early Bird savings until 8 June.
the fix you provided seems to work BUT the bookmark button is limited to content area.. any ideas on how to print it elsewhere in a page? thanks in advance.
As part of Views integration, I found it's completely necessary to solve this request so that we can put flag links in the views easily.
I completely ditched our current hook_link() and rewrote it so that it now uses a theme function, theme_link(). This makes it slightly unconventional in Drupal, but since the link has AJAX behavior (which is also uncommon), I think it's easily justified.
Now in Flag module, you can easily print out a link to AJAX flag an item by using:
It's not perfect yet, but it's a significant improvement. We could potentially provide another wrapper function to just print out the combination of the above, taking just the bookmark name. However, I didn't want to make a theme function that provided all of this, in case we change the API functions we don't want to break all the themes using Flag.
Nate, that's excellent! This improvement is a milestone for this module. You managed to make the code outrageously simple :)
[Injecting cooked HTML into the links is] slightly unconventional in Drupal [...] I think it's easily justified.
I agree.
==
It's good that you folded the node_load() into flag_process_labels(). Now the view handler's render() doesn't have to do an expensive node_load().
Random notes:
- The Views support looks elegant. I see you ditched the pseudo tables trick in favor of relationships. Nice!
- In hook_theme() I think you forgot to declare the 'content_type' argument. BTW, isn't the 'content_type' property found on the $flag object itself? I guess you made it an extra argument for clarity's sake.
- (Maybe Earl would be interested in incorporating _flag_format_plural()'s functionality into views_handler_field_numeric.)
Fantastic, I'll be testing this later today or tomorrow. I'm going to try to print the "flag" next to the nodetitle using the phark image replacement technique. Will report back!
In hook_theme() I think you forgot to declare the 'content_type' argument.
You're right! Thanks I added in these parameters into hook_theme().
BTW, isn't the 'content_type' property found on the $flag object itself? I guess you made it an extra argument for clarity's sake.
The types declared in the flag are what possible types the flag can be placed on. In the theme function we need to pass in these parameters to give the theme function the current context of where it is being printed out (in a node, what the nid is... in the future, possibly in a comment and what the cid is).
isn't the 'content_type' property found on the $flag object itself?
The types declared in the flag are what possible types the flag can be placed on [...]
I knew that. My mistake was that I thought it was the flag definition, not the individual marks, that was associated with a certain content_type. In other words, I thought that if we wanted to flag both comments and nodes as 'offensive', then we'd need to define two different flags, one for each content_type.
I finally got around to testing this, and I suppose I'm doing it wrong because nothing happens. My bookmark is still in the Links section of the node.
I'm sure it's something minor that I'm missing. Baby steps perhaps..
What way do you guys suggest using to print out the link in a custom node.tpl.php file? As soon as I get a response, I'll test it out and do some bug fixing.
Prodigy, I'll check that tomorrow. Meanwhile, remember that:
1. You're dealing with beta, or dev, so don't blame yourself ;-)
2. In D5 theming isn't easy, because you have to write code (this has changed in D6; but, again, since this is beta things haven't been finalized yet).
My bookmark is still in the Links section of the node.
That's ok, and it'll keep staying there unless you edit the flag and uncheck the 'show on page/teaser'. But you can leave it checked for the time being.
Ohhh, so if you don't uncheck show on teaser/full page you can't move the bookmark? I thought it would at worst show 2 (1 where I placed it and 1 in links). I'll attempt this again in the morning! Thanks Moof
I'm curious if there was ever a clear instance of someone successfully moving the 'flag' link out of the links section to somewhere else. My curiosity is related to the fact that I have a content type with its own ".tpl.php" template and I want to 'print' the 'flag' link into a specific area of the node template. Any and all help is much appreciated.
The reason behind this is as follows, for those interested in the details.
The content type is a nodeprofile content type. It is currently used as a type of user profile which is shown on the user's account page. Nodeprofile's method of embedding itself into the user account page deletes the standard links section associated with any node type used as a nodeprofile. My intention was to allow users to favorite each other. However the link doesn't show up anywhere because nodeprofile does away with the link section as I mentioned earlier. However, if I can find a method by which to move the "flag" link out of the links section to somewhere else within the node type then it will show up successfully and users can effectively favorite one another.
I actually sorta solved my problem by means of a crazy work around, but it didn't work right.
I created a view that displayed the specific user profile content type, embedded it into that content types '.tpl.php' template file and then set the argument to show only the nodes of that content type by whatever user's profile you happen to be on. Basically I embedded the user profile within the user profile by means of a view. This allowed me to show the add to fav's ops field (by choosing list view) so that the link would show up. I only added in this field to the view. The problem I found here is that even though the 'flag' link is not global, when you embed it as a field within a view it becomes global and it can only be bookmarked/flagged by one person. Which means only one user can favorite another, and until they unfavorite them no one else can. Which brings me back to why the ability to print the 'flag/bookmark' link wherever I like within the node would be WONDERFUL.
In a hurry, but yes. Upgrade to the flag module, and check the issue queue. Mark this as fixed also, as this is definitely possible. Just follow the directions that are given in the flag issue queue. Also, make sure you're using the latest version of jquery update.
The reason behind this is as follows, for those interested in the details.
You don't need to explain yourself. Being able to put the link anywhere is a crucial feature for this module.
Prodigy was referring to the following issue, which explains how to do this: http://drupal.org/node/279318
(Please let us know that it works for you so that we add this helper function to the next release.)
Eventually, theming and embedding links will be much much easier.
Comments
Comment #1
mooffie commentedComment #2
Fayna commentedI'm interested in this as well. I'd like to be able to replace the links with icons instead (with no text), too :)
Comment #3
quicksketchFayna, you can already replace text with an icon by using a CSS text-replacement method.
http://mezzoblue.com/tests/revised-image-replacement/
I personally use the Phark method on every site I develop.
Comment #4
Fayna commentedThanks!!
Comment #5
ringmod commentedthe fix you provided seems to work BUT the bookmark button is limited to content area.. any ideas on how to print it elsewhere in a page? thanks in advance.
Comment #6
quicksketchAs part of Views integration, I found it's completely necessary to solve this request so that we can put flag links in the views easily.
I completely ditched our current hook_link() and rewrote it so that it now uses a theme function, theme_link(). This makes it slightly unconventional in Drupal, but since the link has AJAX behavior (which is also uncommon), I think it's easily justified.
Now in Flag module, you can easily print out a link to AJAX flag an item by using:
Or, in a practical example:
It's not perfect yet, but it's a significant improvement. We could potentially provide another wrapper function to just print out the combination of the above, taking just the bookmark name. However, I didn't want to make a theme function that provided all of this, in case we change the API functions we don't want to break all the themes using Flag.
Here's the commits:
D5: http://cvs.drupal.org/viewcvs/drupal/contributions/modules/flag/flag.mod...
D6: http://cvs.drupal.org/viewcvs/drupal/contributions/modules/flag/flag.mod...
Comment #7
quicksketchEven though these have been committed, reviews would be appreciated.
Comment #8
mooffie commentedNate, that's excellent! This improvement is a milestone for this module. You managed to make the code outrageously simple :)
I agree.
==
It's good that you folded the node_load() into flag_process_labels(). Now the view handler's render() doesn't have to do an expensive node_load().
Random notes:
- The Views support looks elegant. I see you ditched the pseudo tables trick in favor of relationships. Nice!
- In hook_theme() I think you forgot to declare the 'content_type' argument. BTW, isn't the 'content_type' property found on the $flag object itself? I guess you made it an extra argument for clarity's sake.
- (Maybe Earl would be interested in incorporating _flag_format_plural()'s functionality into views_handler_field_numeric.)
Comment #9
chadchandler commentedFantastic, I'll be testing this later today or tomorrow. I'm going to try to print the "flag" next to the nodetitle using the phark image replacement technique. Will report back!
Comment #10
quicksketchYou're right! Thanks I added in these parameters into hook_theme().
The types declared in the flag are what possible types the flag can be placed on. In the theme function we need to pass in these parameters to give the theme function the current context of where it is being printed out (in a node, what the nid is... in the future, possibly in a comment and what the cid is).
Comment #11
mooffie commentedI knew that. My mistake was that I thought it was the flag definition, not the individual marks, that was associated with a certain content_type. In other words, I thought that if we wanted to flag both comments and nodes as 'offensive', then we'd need to define two different flags, one for each content_type.
Comment #12
quicksketchWe're continuing the content-type discussion here #269814: Option to turn off flag link on 'page'; rename some DB columns. This ticket is fixed.
Comment #13
chadchandler commentedI finally got around to testing this, and I suppose I'm doing it wrong because nothing happens. My bookmark is still in the Links section of the node.
I'm sure it's something minor that I'm missing. Baby steps perhaps..
What way do you guys suggest using to print out the link in a custom node.tpl.php file? As soon as I get a response, I'll test it out and do some bug fixing.
Note: I'm using the latest dev. release.
Comment #14
mooffie commentedProdigy, I'll check that tomorrow. Meanwhile, remember that:
1. You're dealing with beta, or dev, so don't blame yourself ;-)
2. In D5 theming isn't easy, because you have to write code (this has changed in D6; but, again, since this is beta things haven't been finalized yet).
That's ok, and it'll keep staying there unless you edit the flag and uncheck the 'show on page/teaser'. But you can leave it checked for the time being.
Comment #15
chadchandler commentedOhhh, so if you don't uncheck show on teaser/full page you can't move the bookmark? I thought it would at worst show 2 (1 where I placed it and 1 in links). I'll attempt this again in the morning! Thanks Moof
Comment #16
musicmadness commentedI'm curious if there was ever a clear instance of someone successfully moving the 'flag' link out of the links section to somewhere else. My curiosity is related to the fact that I have a content type with its own ".tpl.php" template and I want to 'print' the 'flag' link into a specific area of the node template. Any and all help is much appreciated.
The reason behind this is as follows, for those interested in the details.
The content type is a nodeprofile content type. It is currently used as a type of user profile which is shown on the user's account page. Nodeprofile's method of embedding itself into the user account page deletes the standard links section associated with any node type used as a nodeprofile. My intention was to allow users to favorite each other. However the link doesn't show up anywhere because nodeprofile does away with the link section as I mentioned earlier. However, if I can find a method by which to move the "flag" link out of the links section to somewhere else within the node type then it will show up successfully and users can effectively favorite one another.
I actually sorta solved my problem by means of a crazy work around, but it didn't work right.
I created a view that displayed the specific user profile content type, embedded it into that content types '.tpl.php' template file and then set the argument to show only the nodes of that content type by whatever user's profile you happen to be on. Basically I embedded the user profile within the user profile by means of a view. This allowed me to show the add to fav's ops field (by choosing list view) so that the link would show up. I only added in this field to the view. The problem I found here is that even though the 'flag' link is not global, when you embed it as a field within a view it becomes global and it can only be bookmarked/flagged by one person. Which means only one user can favorite another, and until they unfavorite them no one else can. Which brings me back to why the ability to print the 'flag/bookmark' link wherever I like within the node would be WONDERFUL.
-Regards all.
Comment #17
chadchandler commentedIn a hurry, but yes. Upgrade to the flag module, and check the issue queue. Mark this as fixed also, as this is definitely possible. Just follow the directions that are given in the flag issue queue. Also, make sure you're using the latest version of jquery update.
Comment #18
mooffie commentedYou don't need to explain yourself. Being able to put the link anywhere is a crucial feature for this module.
Prodigy was referring to the following issue, which explains how to do this:
http://drupal.org/node/279318
(Please let us know that it works for you so that we add this helper function to the next release.)
Eventually, theming and embedding links will be much much easier.
Comment #19
musicmadness commentedI did as you said. Had a problem, but it was a typo on my part. Worked. Fixed.
Thanks
Comment #20
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.