I felt it would be overkill to add another module to have this functionality. If these two functions would reference a separate file, it would allow editing and at a later date a GUI could be built to write to this file so non-programmers could create their own tokens.

Let me know your thoughts on this. I may be willing to contribute.

Thanks,

david

/**
* File: token.module
*/

function token_token_values($type, $object = NULL) {
global $user;
global $base_url;
$values = array();

switch ($type) {
case 'global':
$values['user-name'] = $user->uid ? $user->name : variable_get('anonymous', t('Anonymous'));
$values['user-id'] = $user->uid ? $user->uid : 0;
$values['user-mail'] = $user->uid ? $user->mail : '';
$values['site-url'] = $base_url;
$values['site-name'] = variable_get('site_name', t('Drupal'));
$values['site-slogan'] = variable_get('site_slogan', '');
$values['site-mail'] = variable_get('site_mail', '');
$values['site-date'] = format_date(time(), 'short', '', variable_get('date_default_timezone', 0));
$values['site-date-Y-m']= format_date(time(), 'custom', 'Y-m', variable_get('date_default_timezone', 0)); //THE TOKEN I NEEDED
break;
}
return $values;
}

function token_token_list($type = 'all') {
$tokens['global']['user-name'] = t('The name of the currently logged in user.');
$tokens['global']['user-id'] = t('The user ID of the currently logged in user.');
$tokens['global']['user-mail'] = t('The email address of the currently logged in user.');
$tokens['global']['site-url'] = t('The url of the current Drupal website.');
$tokens['global']['site-name'] = t('The name of the current Drupal website.');
$tokens['global']['site-slogan'] = t('The slogan of the current Drupal website.');
$tokens['global']['site-mail'] = t('The contact email address for the current Drupal website.');
$tokens['global']['site-date'] = t("The current date on the site's server.");
$tokens['global']['site-date-Y-m']= t("The current Year-month on the site's server: ".format_date(time(), 'custom', 'Y-m', variable_get('date_default_timezone', 0))); //THE TOKEN I NEEDED
return $tokens;
}

Comments

greggles’s picture

Status: Active » Closed (duplicate)

Custom tokens can be provided via the Token Node Tokens module.

Support for an increased number of global site dates is in #236596: Add support for date parts YYYY, MM, and DD

greggles’s picture

I should say that the token node tokens module needs help to bring it to full release status and to port it to 6.x.

And also that issue #236596 is kind of muddled and could use a review.

Thanks for your offer to help - I look forward to your help in the future.