You are here

function flag_create_link in Flag 7.3

Same name and namespace in other branches
  1. 5 flag.module \flag_create_link()
  2. 6.2 flag.module \flag_create_link()
  3. 6 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 theme preprocessor for node.tpl.php:

$variables['my_flag_link'] = flag_create_link('bookmarks', $node->nid);

Parameters

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

$entity_id: The entity ID to check for flagging, for example a node ID.

$variables: An array of further variables to pass to theme('flag'). For the full list of parameters, see flag.tpl.php. Of particular interest:

  • after_flagging: Set to TRUE if this flag link is being displayed as the result of a flagging action.
  • errors: An array of error messages.

Return value

The HTML for the themed flag link.

2 calls to flag_create_link()
flag_flag_link_content_type_render in plugins/content_types/flag_link/flag_link.inc
Render callback.
flag_tokens in ./flag.tokens.inc
Implements hook_tokens().

File

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

Code

function flag_create_link($flag_name, $entity_id, $variables = array()) {
  $flag = flag_get_flag($flag_name);
  if (!$flag) {

    // Flag does not exist.
    return;
  }
  if (!$flag
    ->access($entity_id) && (!$flag
    ->is_flagged($entity_id) || !$flag
    ->access($entity_id, 'flag'))) {

    // User has no permission to use this flag.
    return;
  }
  return $flag
    ->theme($flag
    ->is_flagged($entity_id) ? 'unflag' : 'flag', $entity_id, $variables);
}