1 token_example.tokens.inc token_example_token_info()

Implements hook_token_info().

Related topics

File

modules/examples/token_example/token_example.tokens.inc, line 12
Token callbacks for the token_example module.

Code

function token_example_token_info() {
  // Add two different token types. The first is the generic text format. The
  // second is the user's default text format, which is itself a 'format' token
  // type so it can be used directly.
  $info['types']['format'] = array(
    'name' => t('Text formats'),
    'description' => t('Tokens related to text formats.'),
    'needs-data' => 'format',
  );
  $info['types']['default-format'] = array(
    'name' => t('Default text format'),
    'description' => t("Tokens related to the currently logged in user's default text format."),
    'type' => 'format',
  );

  // Tokens for the text format token type.
  $info['tokens']['format']['id'] = array(
    'name' => t('ID'),
    'description' => t("The unique ID of the text format."),
  );
  $info['tokens']['format']['name'] = array(
    'name' => t('Name'),
    'description' => t("The name of the text format."),
  );

  // Node tokens.
  $info['tokens']['node']['body-format'] = array(
    'name' => t('Body text format'),
    'description' => t("The name of the text format used on the node's body field."),
    'type' => 'format',
  );

  // Comment tokens.
  if (module_exists('comment')) {
    $info['tokens']['comment']['body-format'] = array(
      'name' => t('Body text format'),
      'description' => t("The name of the text format used on the comment's body field."),
      'type' => 'format',
    );
  }

  return $info;
}