You are here

function realname_preprocess_user_picture in Real Name 6

Override template_preprocess_user_picture() to display a user's realname.

File

./realname.module, line 367

Code

function realname_preprocess_user_picture(&$variables) {
  if (!empty($variables['picture'])) {

    // Replace the alt text 'username's picture' with 'realname's picture.'
    $account = $variables['account'];
    $not_real_name = $account->name ? $account->name : variable_get('anonymous', t('Anonymous'));
    $real_name = isset($account->realname) ? $account->realname : realname_make_name($account);
    if ($real_name && $real_name != $not_real_name) {
      $not_real_name_alt = check_plain(t("@user's picture", array(
        '@user' => $not_real_name,
      )));
      $real_name_alt = check_plain(t("@user's picture", array(
        '@user' => $real_name,
      )));
      $variables['picture'] = str_replace($not_real_name_alt, $real_name_alt, $variables['picture']);

      // Intentionally clone the account object and set the name property
      // to the user's realname so that any further implementations of
      // hook_preprocess_user_picture() can just use $account->name.
      $variables['account'] = drupal_clone($account);
      $variables['account']->name = $real_name;
    }
  }
}