atrium_username is a Drupal feature for managing user name display:
* a lightweight alternative to realname module;
* "works" before theme layer
* uses the node title of the user profile
3. atrium_username
• a Drupal feature for managing user name display;
• a lightweight alternative to realname module;
• "works" before theme layer
• uses the node title of the user profile
function atrium_username_get_name($uid) {
static $users = array();
if (!isset($users[$uid])) {
// get data from db DIRECTLY
$users[$uid] = db_result(db_query("SELECT title
FROM {node} WHERE type='profile' AND uid=%d", $uid));
}
return $users[$uid];
}
It doesn't implements its own theme_username allowing another theme to
override it.
3
13. User Name Field
render_link() method
function render_link($data, $values) {
// get uid field name
$field_uid = isset($this->aliases['uid']) ? $this->aliases['uid'] : 'uid';
if (!empty($this->options['link_to_user']) || !empty($this-
>options['overwrite_anonymous'])) {
$account = new stdClass();
$account->uid = $values->{$field_uid};
if (!empty($this->options['overwrite_anonymous']) && !$account->uid) {
// This is an anonymous user, and we're overriting the text.
return check_plain($this->options['anonymous_text']);
}
elseif (!empty($this->options['link_to_user'])) {
$account->name = $values->{$this->field_alias};
return theme('username', $account);
}
}
// Otherwise, there's no special handling, so try to return atrium_username.
if(isset($values->{$field_uid})) {
$atrium_username = atrium_username_get_name($values->{$field_uid});
return $atrium_username ? $atrium_username : $data;
}
else {
return $data;
}
}
13
16. Casetracker – issue page
Function atrium_username_theme_casetracker_comment_changes
case 'assign_to':
$old->{$field} = atrium_username_get_name($old-
>{$field}) ? atrium_username_get_name($old->{$field}) :
check_plain(casetracker_get_name($old->{$field}));
$new->{$field} = atrium_username_get_name($new-
>{$field}) ? atrium_username_get_name($new->{$field}) :
check_plain(casetracker_get_name($new->{$field}));
break;
Unfortunately we have to rewrite everything as the lines to be changed are
inside a switch/case with no other options.
Only the case 'assign_to' is modified.
16
18. Casetracker – issue page
hook_form_alter
if(!empty($form['casetracker']['assign_to']['#options'])) {
$assign_to = $form['casetracker']['assign_to']
['#options'];
foreach($assign_to as $key => $value) {
$uid = casetracker_get_uid($key);
$atrium_username = atrium_username_get_name($uid);
$name = $atrium_username ? $atrium_username : $value;
$form['casetracker']['assign_to']['#options'][$key] =
$name;
}
}
Radio options are set at theme level
(theme_casetracker_case_form_common) but this is a form
(comment_form()) so we can hook_form_alter:
18
20. Casetracker – issue filter
hook_form_alter
if($form_id=='views_exposed_form' && $form['#id']=='views-
exposed-form-casetracker-cases-page-1') {
foreach($form['assign_to']['#options'] as $uid => $value) {
if(is_int($uid) && $uid>0) {
$atrium_username = atrium_username_get_name($uid);
if(!empty($atrium_username)) {
$form['assign_to']['#options'][$uid] =
$atrium_username . "~";
}
}
}
}
The "Filter results" block is an exposed filter from the casetracker_cases
view.
It's a form so we user hook_form_alter to modify user names
20