realname.tokens.inc 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * @file
  4. * Builds placeholder replacement tokens for realname.
  5. */
  6. /**
  7. * Implements hook_token_info().
  8. */
  9. function realname_token_info() {
  10. $info['tokens']['user']['name-raw'] = array(
  11. 'name' => t('Raw name'),
  12. 'description' => t('The raw login name of the user account, unprocessed by the RealName module.'),
  13. );
  14. return $info;
  15. }
  16. /**
  17. * Implements hook_token_info_alter().
  18. */
  19. function realname_token_info_alter(&$info) {
  20. // Since the [user:name] token uses format_username(), its meta-data should
  21. // be altered to reflect that it will be the real name.
  22. $info['tokens']['user']['name']['name'] = t('Real name');
  23. $info['tokens']['user']['name']['description'] = t('The real name of the user account.');
  24. }
  25. /**
  26. * Implements hook_tokens().
  27. */
  28. function realname_tokens($type, $tokens, array $data = array(), array $options = array()) {
  29. $replacements = array();
  30. $sanitize = !empty($options['sanitize']);
  31. if ($type == 'user' && !empty($data['user'])) {
  32. $account = $data['user'];
  33. foreach ($tokens as $name => $original) {
  34. switch ($name) {
  35. case 'name-raw':
  36. $replacements[$original] = $sanitize ? check_plain($account->name) : $account->name;
  37. break;
  38. }
  39. }
  40. }
  41. return $replacements;
  42. }