In Drupal 7, teasers have contextual links.
Flag should provide this option for teasers in addition to the present comment-area links.
Here's the generic basics of how: http://drupal.org/node/1089922
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | flag_contextual.patch | 2.68 KB | quicksketch |
| #7 | flag-add-contextual-links-1198530-7.patch | 2.37 KB | semiaddict |
| #6 | flag-add-contextual-links-1198530-6.patch | 1.7 KB | semiaddict |
Comments
Comment #1
quicksketchI agree this would be a great feature and included in the D7 version as part of the Flag core module. If anyone has time to construct a patch I'd be happy to review it, otherwise I'll add this to the long-term todo list.
Comment #2
jaydub commentedIt would appear that in order to support the contextual links the menu callback used (flag/%/%flag/% in this case) needs to be configured as type MENU_LOCAL_TASK. Right now the main flag menu callback is of type MENU_CALLBACK. Not sure what the implications would be of converting to MENU_LOCAL_TASK. If the menu were to be a local task it would also need to have a parent menu path.
In http://drupal.org/node/1089922
"// To use local task menu items, there must be a parent page."
Comment #3
semiaddict commentedIf someone could help me figure out which function I need to use to generate the flag/unflag urls, I'd be pleased to put a patch together for adding contextual links.
@jaydub, I've tested out the Custom Contextual Links module (http://drupal.org/project/ccl), and from what I see, I don't think the menu callback needs to be a MENU_LOCAL_TASK. Where did you get this info from ?
Comment #4
jaydub commented@semiaddict What I stated about contextual links is for the contextual links feature that is part of Drupal 7 core as mentioned in http://drupal.org/documentation/modules/contextual
I can't speak to what is the case for a contributed module. I would imagine that ideally if this feature is in the Flag module that it uses the core module and not require a contrib module.
Comment #5
semiaddict commented@jaydub, I totally agree that using the core module is the way to go. I simply pointed out the cct module as it seems to be able to create contextual links for almost any url, not only MENU_LOCAL_TASK, by simply implementing the core hook "hook_contextual_links_view_alter". So it should be possible to do so for the flag links (without the need of the cct module that is).
The only thing that keeps me from doing this is that I can't find a function in the flag module that generates a flag or unflag url. I found the flag_create_link function, but it generates a theme link, not a simple url.
Do I also need to implement such a function, or does one already exist ?
Comment #6
semiaddict commentedAttached is my first attempt at adding contextual links for flagging/unflagging nodes.
To simplify the code I made it a sub-module.
I ended up using the function flag_flag_link (declared in flag.module) to generate the flag url. I hope this is the right way to do it ?
For now all flags that can be applied to a node are added to the contextual links.
But I will soon be adding some options in the admin form to allow the selection of the flags to add as contextual links.
Comment #7
semiaddict commentedI got more time to work on it and found out it would actually be easier to put this functionality directly into the main module.
Attached is a new patch (it replaces the previous one), which adds a checkbox in a flag's "Display options" to show the flag link in the contextual links.
Comment #8
berdyshev commentedthanks for patch. it works for me on the beta6 version
Comment #9
quicksketchThanks for the patch guys. This patch still needed a little work in that it had a few coding standards problems (http://drupal.org/coding-standards) but the overall approach looks good. Rather than using flag_flag_link() directly, I updated the patch to use $flag->render(), which results in the contextual link supporting AJAX toggling. Overall great patch though. Committed attached version to the project.