Commit 2c413bf0 authored by Steve Gerbino's avatar Steve Gerbino

Adding realname_registration.tokens.inc to master branch

parent eb65187b
<?php
/**
* @file
* Token callbacks for the realname_registration module.
*/
/**
* Implements hook_token_info().
*/
function realname_registration_token_info() {
$user['first-name'] = array(
'name' => t('First name'),
'description' => t("The first name of the user."),
);
$user['last-name'] = array(
'name' => t('Last name'),
'description' => t("The last name of the user."),
);
$user['first-initial'] = array(
'name' => t('First inital'),
'description' => t("The first initial of the user."),
);
$user['last-initial'] = array(
'name' => t('Last initial'),
'description' => t("The last initial of the user."),
);
return array( 'tokens' => array('user' => $user) );
}
/**
* Implements hook_tokens().
*/
function realname_registration_tokens($type, $tokens, array $data = array(), array $options = array()) {
$sanitize = !empty($options['sanitize']);
$replacements = array();
$field_firstname = variable_get('realname_registration_firstname_field');
$field_lastname = variable_get('realname_registration_lastname_field');
if(isset($field_firstname) && isset($field_lastname)) {
if ($type == 'user' && !empty($data['user'])) {
$account = $data['user'];
foreach ($tokens as $name => $original) {
switch ($name) {
case 'first-name':
$replacements[$original] = !empty($account->$field_firstname) ? $account->{$field_firstname}['und']['0']['value'] : t('not yet available');
break;
case 'last-name':
$replacements[$original] = !empty($account->$field_lastname) ? $account->{$field_lastname}['und']['0']['value'] : t('not yet available');
break;
case 'first-initial':
$replacements[$original] = !empty($account->$field_firstname) ? drupal_substr($account->{$field_firstname}['und']['0']['value'], 0, 1) : t('not yet available');
break;
case 'last-initial':
$replacements[$original] = !empty($account->$field_lastname) ? drupal_substr($account->{$field_lastname}['und']['0']['value'], 0, 1) : t('not yet available');
break;
}
}
}
}
if ($type == 'current-user') {
$account = user_load($GLOBALS['user']->uid);
$replacements += token_generate('user', $tokens, array('user' => $account), $options);
}
return $replacements;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment