You are here

function gravatar_form_user_profile_form_alter in Gravatar integration 6

Same name and namespace in other branches
  1. 7 gravatar.module \gravatar_form_user_profile_form_alter()

Implements hook_form_FORM_ID_alter().

@todo Improve message shown to user.

File

./gravatar.module, line 243
Integrates gravatar service for user pictures.

Code

function gravatar_form_user_profile_form_alter(&$form, $form_state) {
  if ($form['_category']['#value'] == 'account' && isset($form['picture']) && variable_get('user_pictures', 0) && ($account = $form['_account']['#value']) && user_access('use gravatar', $account)) {

    // Add the default user picture preview.
    if (!isset($form['picture']['current_picture']) && ($picture = theme('user_picture', $account))) {
      $form['picture']['current_picture'] = array(
        '#value' => $picture,
        '#weight' => -10,
      );
    }
    if (user_access('disable own gravatar', $account)) {
      $form['picture']['gravatar'] = array(
        '#type' => 'checkbox',
        '#title' => t('If you have a <a href="@gravatar-check">valid Gravatar</a> associated with your e-mail address, use it for your user picture.', array(
          '@gravatar-check' => 'http://en.gravatar.com/site/check/' . $account->mail,
        )),
        '#description' => t('Your Gravatar will not be shown if you upload a user picture.'),
        '#default_value' => isset($account->gravatar) ? $account->gravatar : 1,
        '#disabled' => !empty($account->picture),
      );
    }
    else {
      $form['picture']['gravatar'] = array(
        '#type' => 'item',
        '#value' => t('If you have a <a href="@gravatar-check">valid gravatar</a> associated with your e-mail address, it will be used for your user picture.', array(
          '@gravatar-check' => 'http://en.gravatar.com/site/check/' . $account->mail,
        )),
        '#description' => t('Your Gravatar will not be shown if you upload a user picture.'),
      );
    }
  }
}