Chris@0: /** Chris@0: * Implements hook_tokens(). Chris@0: */ Chris@0: function {{ machine_name }}_tokens($type, $tokens, array $data = array(), array $options = array()) { Chris@0: $url_options = array('absolute' => TRUE); Chris@0: if (isset($options['language'])) { Chris@0: $url_options['language'] = $options['language']; Chris@0: $language_code = $options['language']->language; Chris@0: } Chris@0: else { Chris@0: $language_code = NULL; Chris@0: } Chris@0: $sanitize = !empty($options['sanitize']); Chris@0: Chris@0: $replacements = array(); Chris@0: Chris@0: if ($type == 'node' && !empty($data['node'])) { Chris@0: $node = $data['node']; Chris@0: Chris@0: foreach ($tokens as $name => $original) { Chris@0: switch ($name) { Chris@0: // Simple key values on the node. Chris@0: case 'nid': Chris@0: $replacements[$original] = $node->nid; Chris@0: break; Chris@0: Chris@0: case 'title': Chris@0: $replacements[$original] = $sanitize ? check_plain($node->title) : $node->title; Chris@0: break; Chris@0: Chris@0: case 'edit-url': Chris@0: $replacements[$original] = url('node/' . $node->nid . '/edit', $url_options); Chris@0: break; Chris@0: Chris@0: // Default values for the chained tokens handled below. Chris@0: case 'author': Chris@0: $name = ($node->uid == 0) ? variable_get('anonymous', t('Anonymous')) : $node->name; Chris@0: $replacements[$original] = $sanitize ? filter_xss($name) : $name; Chris@0: break; Chris@0: Chris@0: case 'created': Chris@0: $replacements[$original] = format_date($node->created, 'medium', '', NULL, $language_code); Chris@0: break; Chris@0: } Chris@0: } Chris@0: Chris@0: if ($author_tokens = token_find_with_prefix($tokens, 'author')) { Chris@0: $author = user_load($node->uid); Chris@0: $replacements += token_generate('user', $author_tokens, array('user' => $author), $options); Chris@0: } Chris@0: Chris@0: if ($created_tokens = token_find_with_prefix($tokens, 'created')) { Chris@0: $replacements += token_generate('date', $created_tokens, array('date' => $node->created), $options); Chris@0: } Chris@0: } Chris@0: Chris@0: return $replacements; Chris@0: }