You are here

function flag_create_link in Flag 5

Same name and namespace in other branches
  1. 6.2 flag.module \flag_create_link()
  2. 6 flag.module \flag_create_link()
  3. 7.3 flag.module \flag_create_link()
  4. 7.2 flag.module \flag_create_link()

A utility function for outputting a flag link.

You should call this function from your template when you want to put the link on the page yourself. For example, you could call this function from your 'node.tpl.php':

<?php print flag_create_link('bookmarks', $node->nid); ?>

Parameters

$flag_name: The "machine readable" name of the flag; e.g. 'bookmarks'.

$content_id: The content ID to check for flagging. This is usually a node ID.

File

./flag.module, line 1103
The Flag module.

Code

function flag_create_link($flag_name, $content_id) {
  $flag = flag_get_flag($flag_name);
  if (!$flag) {

    // Flag does not exist.
    return;
  }
  if (!$flag
    ->user_access()) {

    // User has no permission to use this flag.
    return;
  }
  if (!$flag
    ->applies_to_content_id($content_id)) {

    // Flag does not apply to this content.
    return;
  }
  return $flag
    ->theme($flag
    ->is_flagged($content_id) ? 'unflag' : 'flag', $content_id);
}