You are here

function flag_token_info in Flag 7.2

Same name and namespace in other branches
  1. 8.4 flag.tokens.inc \flag_token_info()
  2. 7.3 flag.tokens.inc \flag_token_info()

Implements of hook_token_info().

File

./flag.tokens.inc, line 11
Flag module tokens support.

Code

function flag_token_info() {
  $types = array();
  $tokens = array();

  // Flag tokens.
  $types['flag'] = array(
    'name' => t('Flags'),
    'description' => t('Tokens related to flag data.'),
    'needs-data' => 'flag',
  );
  $tokens['flag']['name'] = array(
    'name' => t('Flag name'),
    'description' => t('The flag machine-readable name.'),
  );
  $tokens['flag']['title'] = array(
    'name' => t('Flag title'),
    'description' => t('The human-readable flag title.'),
  );

  // Flage action tokens.
  $types['flag-action'] = array(
    'name' => t('Flag actions'),
    'description' => t('Tokens available in response to a flag action being executed by a user.'),
    'needs-data' => 'flag-action',
  );
  $tokens['flag-action']['action'] = array(
    'name' => t('Flag action'),
    'description' => t('The flagging action taking place, either "flag" or "unflag".'),
  );
  $tokens['flag-action']['content-url'] = array(
    'name' => t('Flag content URL'),
    'description' => t('The URL of the content being flagged.'),
  );
  $tokens['flag-action']['content-title'] = array(
    'name' => t('Flag content title'),
    'description' => t('The title of the content being flagged.'),
  );
  $tokens['flag-action']['content-type'] = array(
    'name' => t('Flag content type'),
    'description' => t('The type of content being flagged, such as <em>node</em> or <em>comment</em>.'),
  );
  $tokens['flag-action']['content-id'] = array(
    'name' => t('Flag content ID'),
    'description' => t('The ID of content being flagged, may be a nid or cid.'),
  );
  $tokens['flag-action']['count'] = array(
    'name' => t('Flag count'),
    'description' => t('The current count total for this flag.'),
  );

  // Add tokens for the flag count available at the node/comment/user level.
  foreach (flag_get_types() as $flag_type) {
    $flags = flag_get_flags($flag_type);
    foreach ($flags as $flag) {
      $tokens[$flag_type]['flag-' . str_replace('_', '-', $flag->name) . '-count'] = array(
        'name' => t('@flag flag count', array(
          '@flag' => $flag
            ->get_title(),
        )),
        'description' => t('Total flag count for flag @flag', array(
          '@flag' => $flag
            ->get_title(),
        )),
      );
      $tokens[$flag_type]['flag-' . str_replace('_', '-', $flag->name) . '-link'] = array(
        'name' => t('@flag flag link', array(
          '@flag' => $flag
            ->get_title(),
        )),
        'description' => t('Flag/unflag link for @flag', array(
          '@flag' => $flag
            ->get_title(),
        )),
      );
    }
  }
  return array(
    'types' => $types,
    'tokens' => $tokens,
  );
}