Commit 139fc2ef authored by Steve Gerbino's avatar Steve Gerbino

Issue #1203330 by sw3b: Added token capabilities for Profile2

integration.
parent 6123aad5
......@@ -32,7 +32,6 @@ function realname_registration_token_info() {
'name' => t('Last initial'),
'description' => t("The last initial of the user."),
);
return array( 'tokens' => array('user' => $user) );
}
......@@ -47,33 +46,91 @@ function realname_registration_tokens($type, $tokens, array $data = array(), arr
$field_middlename = variable_get('realname_registration_middlename_field');
$field_lastname = variable_get('realname_registration_lastname_field');
$field_firstname_profile_type = variable_get('realname_registration_profile2_firstname_field_profile_name');
$field_middlename_profile_type = variable_get('realname_registration_profile2_middlename_field_profile_name');
$field_lastname_profile_type = variable_get('realname_registration_profile2_lastname_field_profile_name');
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'] : '';
if (variable_get('realname_registration_use_profile2_firstname_field')) {
$result = db_query('SELECT p.pid FROM {profile} AS p WHERE p.uid = :uid AND p.type = :type', array(':uid' => $account->uid, ':type' => $field_firstname_profile_type));
foreach ($result as $record) {
$profile2_firstname = profile2_load($record->pid);
}
$replacements[$original] = !empty($profile2_firstname->$field_firstname) ? $profile2_firstname->{$field_firstname}['und']['0']['value'] : '';
}
else {
$replacements[$original] = !empty($account->$field_firstname) ? $account->{$field_firstname}['und']['0']['value'] : '';
}
break;
case 'middle-name':
$replacements[$original] = !empty($account->$field_middlename) ? $account->{$field_middlename}['und']['0']['value'] : '';
if (variable_get('realname_registration_use_profile2_middlename_field')) {
$result = db_query('SELECT p.pid FROM {profile} AS p WHERE p.uid = :uid AND p.type = :type', array(':uid' => $account->uid, ':type' => $field_middlename_profile_type));
foreach ($result as $record) {
$profile2_middlename = profile2_load($record->pid);
}
$replacements[$original] = !empty($profile2_middlename->$field_middlename) ? $profile2_middlename->{$field_middlename}['und']['0']['value'] : '';
}
else {
$replacements[$original] = !empty($account->$field_middlename) ? $account->{$field_middlename}['und']['0']['value'] : '';
}
break;
case 'last-name':
$replacements[$original] = !empty($account->$field_lastname) ? $account->{$field_lastname}['und']['0']['value'] : '';
if (variable_get('realname_registration_use_profile2_lastname_field')) {
$result = db_query('SELECT p.pid FROM {profile} AS p WHERE p.uid = :uid AND p.type = :type', array(':uid' => $account->uid, ':type' => $field_lastname_profile_type));
foreach ($result as $record) {
$profile2_lastname = profile2_load($record->pid);
}
$replacements[$original] = !empty($profile2_lastname->$field_lastname) ? $profile2_lastname->{$field_lastname}['und']['0']['value'] : '';
}
else {
$replacements[$original] = !empty($account->$field_lastname) ? $account->{$field_lastname}['und']['0']['value'] : '';
}
break;
case 'first-initial':
$replacements[$original] = !empty($account->$field_firstname) ? drupal_substr($account->{$field_firstname}['und']['0']['value'], 0, 1) : '';
if (variable_get('realname_registration_use_profile2_firstname_field')) {
$result = db_query('SELECT p.pid FROM {profile} AS p WHERE p.uid = :uid AND p.type = :type', array(':uid' => $account->uid, ':type' => $field_firstname_profile_type));
foreach ($result as $record) {
$profile2_firstname = profile2_load($record->pid);
}
$replacements[$original] = !empty($profile2_firstname->$field_firstname) ? drupal_substr($profile2_firstname->{$field_firstname}['und']['0']['value'], 0, 1) : '';
}
else {
$replacements[$original] = !empty($account->$field_firstname) ? drupal_substr($account->{$field_firstname}['und']['0']['value'], 0, 1) : '';
}
break;
case 'middle-initial':
$replacements[$original] = !empty($account->$field_middlename) ? drupal_substr($account->{$field_middlename}['und']['0']['value'], 0, 1) : '';
if (variable_get('realname_registration_use_profile2_middlename_field')) {
$result = db_query('SELECT p.pid FROM {profile} AS p WHERE p.uid = :uid AND p.type = :type', array(':uid' => $account->uid, ':type' => $field_middlename_profile_type));
foreach ($result as $record) {
$profile2_middlename = profile2_load($record->pid);
}
$replacements[$original] = !empty($profile2_middlename->$field_middlename) ? drupal_substr($profile2_middlename->{$field_middlename}['und']['0']['value'], 0, 1) : '';
}
else {
$replacements[$original] = !empty($account->$field_middlename) ? drupal_substr($account->{$field_middlename}['und']['0']['value'], 0, 1) : '';
}
break;
case 'last-initial':
$replacements[$original] = !empty($account->$field_lastname) ? drupal_substr($account->{$field_lastname}['und']['0']['value'], 0, 1) : '';
if (variable_get('realname_registration_use_profile2_lastname_field')) {
$result = db_query('SELECT p.pid FROM {profile} AS p WHERE p.uid = :uid AND p.type = :type', array(':uid' => $account->uid, ':type' => $field_lastname_profile_type));
foreach ($result as $record) {
$profile2_lastname = profile2_load($record->pid);
}
$replacements[$original] = !empty($profile2_lastname->$field_lastname) ? drupal_substr($profile2_lastname->{$field_lastname}['und']['0']['value'], 0, 1) : '';
}
else {
$replacements[$original] = !empty($account->$field_lastname) ? drupal_substr($account->{$field_lastname}['und']['0']['value'], 0, 1) : '';
}
break;
}
}
......
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