The Submitted By module allows a site admin to re-configure the "submitted by" line for nodes and comments. It uses tokens to build the text. If this module supplied tokens, then badges could be included in the "submitted by" area.

Comments

ao5357’s picture

[Note: see #982988 for a patch (to current dev) containing the token pieces that are unfamiliar]

The following code, specifically dealing with $type 'user', allows for quick token replacement of badges for a user:

/**
 * Implements hook_token_values().
 */
function user_badges_token_values($type, $object = NULL) {
  if ($type == 'userbadge' && !is_null($object)) {
    return array(
      'bid' => $object->bid,
      'name' => $object->name,
      'image' => $object->image,
      'href' => $object->href,
      'ubid' => $object->ubid,
      'earned' => $object->earned,
      'tid' => $object->tid
      );
  }
  if ($type == 'user' && !is_null($object)) {
    return array(
      'badges' => user_badges_for_uid($object->uid),
      );
  }
}

/**
 * Implements hook_token_list().
 */
function user_badges_token_list($type = 'all') {
  $tokens = array();
  if ($type == 'userbadge' || $type == 'all') {
    $tokens['userbadge']['bid'] = t("The badge id number");
    $tokens['userbadge']['name'] = t("The badge name");
    $tokens['userbadge']['image'] = t("The path to the badge image");
    $tokens['userbadge']['href'] = t("The path to the badge info page");
    $tokens['userbadge']['ubid'] = t("The user badge id number");
    $tokens['userbadge']['earned'] = t("Timestamp when the badge was earned");
    $tokens['userbadge']['tid'] = t("The taxonomy term associated with the badge");
  }
  if ($type == 'user' || $type == 'all') {
    $tokens['user']['badges'] = t('A user\'s badges');
  }
  return $tokens;
}