How to add a non-AJAX link on a page

eliza411 - March 17, 2009 - 15:57
Project:Flag
Version:5.x-1.1
Component:User interface
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed
Description

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.

#1

quicksketch - March 17, 2009 - 19:26

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.

<?php
  $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);
  }
?>

#2

mooffie - March 18, 2009 - 02:08

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 $options parameter to flag_create_link()

#3

quicksketch - March 18, 2009 - 03:27

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.

#4

halstead - March 18, 2009 - 06:45

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.

#5

quicksketch - March 18, 2009 - 05:39

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 $options parameter to flag_create_link() done. Or alternatively start working on a patch for #405580: Add $options 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.

#6

opensanta - May 17, 2009 - 16:06
Component:Code» User interface
Status:active» fixed

Marking as fixed.

#7

System Message - May 31, 2009 - 16:10
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.