Is it possible have an AJAX flag link in the teaser of a node and a regular flag link in the full node?

I know that with views I can create a regular link, one that reloads the page, regardless of what settings I have on an individual flag.
I'm hoping I could make the same kind of choice in a template file.

Thanks in advance for any help you can provide.

Comments

quicksketch’s picture

You can, but you can't use the flag_create_link() function. You'll need to manually set the link_type type and then do the theming yourself.

  $flag = flag_get_flag($flag_name);
  if ($flag->user_access() && $flag->applies_to_content_id($content_id)) {
    $flag->link_type = 'normal'; // Or 'toggle' for AJAX.
    print $flag->theme($flag->is_flagged($node->nid) ? 'unflag' : 'flag', $node->nid);
  }
mooffie’s picture

Nate, that code probably isn't forward-compatible (we're planning to streamline the access interface, don't we?).

I've opened a feature request: #405580: Add $variables parameter to flag_create_link()

quicksketch’s picture

Yes, it's likely that the code above would eventually change (say in a 2.x version), I really like mooffie's suggestion of making flag_create_link() take an argument, seems like it could be extremely useful.

halstead’s picture

Removed a module hack that let us get a bunch of work done. Code from reply #1 does the same thing without changing the module.

quicksketch’s picture

Whoa whoa whoa! Hacking a module (even temporarily) is a much worse solution. I'd suggest using my code from #1 until we get #405580: Add $variables parameter to flag_create_link() done. Or alternatively start working on a patch for #405580: Add $variables parameter to flag_create_link() and then you don't need to worry about upgrading if your site uses a patch that will eventually be committed.

mitchell’s picture

Component: Code » User interface
Status: Active » Fixed

Marking as fixed.

Status: Fixed » Closed (fixed)

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