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

Comments

quicksketch’s picture

I 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.

jaydub’s picture

It 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."

semiaddict’s picture

If 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 ?

jaydub’s picture

@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.

semiaddict’s picture

@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 ?

semiaddict’s picture

Status: Active » Needs work
StatusFileSize
new1.7 KB

Attached 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.

semiaddict’s picture

Status: Needs work » Needs review
StatusFileSize
new2.37 KB

I 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.

berdyshev’s picture

Status: Needs review » Reviewed & tested by the community

thanks for patch. it works for me on the beta6 version

quicksketch’s picture

Status: Reviewed & tested by the community » Fixed
StatusFileSize
new2.68 KB

Thanks 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.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.