You are here

function uuid_token_info in Universally Unique IDentifier 7

Implements hook_token_info().

File

./uuid.tokens.inc, line 11
Builds placeholder replacement tokens for uuid-related data.

Code

function uuid_token_info() {
  $tokens = array();
  foreach (entity_get_info() as $entity_type => $info) {
    if (isset($info['uuid']) && $info['uuid'] == TRUE && !empty($info['entity keys']['uuid'])) {
      $token_type = !empty($info['token type']) ? $info['token type'] : $entity_type;
      $tokens['tokens'][$token_type][$info['entity keys']['uuid']] = array(
        'name' => t('@entity_type UUID', array(
          '@entity_type' => $info['label'],
        )),
        'description' => t('The universally unique ID of the @entity', array(
          '@entity' => drupal_strtolower($info['label']),
        )),
      );
      if (!empty($info['entity keys']['revision uuid'])) {
        $tokens['tokens'][$token_type][$info['entity keys']['revision uuid']] = array(
          'name' => t('@entity_type revision UUID', array(
            '@entity_type' => $info['label'],
          )),
          'description' => t('The universally unique revision ID of the @entity', array(
            '@entity' => drupal_strtolower($info['label']),
          )),
        );
      }
    }
  }
  return $tokens;
}