Markus
Markus

Reputation: 452

Drupal retrieve first name instead of name/realname?

How can I retrieve the first name instead of name (raw username) or realname, so I can use it in an email template variable !username?

$variables['!username'] = $params['account']->realname;

http://cgit.drupalcode.org/faq_ask/tree/faq_ask.module?id=be753ca5c5fe51f33c0515999ceb3a4179298da8#n1052

Not sure if that relates to realname or perhaps where 'account' is defined to something...?

I created a field for first name that gets pulled by LDAP to provide for realname and have the token [user:field-first-name].

Can I pull this from the token somehow?

Update - code where user load is used:

$account = user_load($expert->uid);
        $params = array(
          'category' => is_object($term)?$term->tid:-1,
          'question' => $node->title,
          'question_details' => $node->detailed_question,
          'nid' => $node->nid,
          'creator' => theme('username', array('account' => user_load($node->uid), 'plain' => TRUE)),
          'account' => $account,
        );

I tried

$account = user_load($expert->uid);
$first_name = $account->field_first_name['und'][0]['value'];
        $params = array(
          'category' => is_object($term)?$term->tid:-1,
          'question' => $node->title,
          'question_details' => $node->detailed_question,
          'nid' => $node->nid,
          'creator' => theme('username', array('account' => user_load($node->uid), 'plain' => TRUE)),
          'account' => $first_name,

Upvotes: 1

Views: 324

Answers (1)

Daniela
Daniela

Reputation: 454

If you created a custom field for the first name and want to access it using the user email, you can do it like this:

$user = user_load_by_mail($mail); 
$first_name = $user->field_first_name['und'][0]['value'];

Upvotes: 2

Related Questions