You are here

function profile2_form_user_profile_form_alter in Profile 2 7.2

Same name and namespace in other branches
  1. 7 profile2.module \profile2_form_user_profile_form_alter()

Implements hook_form_FORM_ID_alter() for the user edit form.

See also

profile2_form_validate_handler

profile2_form_submit_handler

File

./profile2.module, line 585
Support for configurable user profiles.

Code

function profile2_form_user_profile_form_alter(&$form, &$form_state) {
  global $user;
  if (($type = profile2_get_types($form['#user_category'])) && $type->userCategory) {
    if (empty($form_state['profiles'])) {
      $profile = profile2_load_by_user($form['#user'], $form['#user_category']);
      if (empty($profile)) {
        $profile = profile2_create(array(
          'type' => $form['#user_category'],
          'uid' => $form['#user']->uid,
        ));
        $profile->is_new = TRUE;
      }
      $form_state['profiles'][$profile->type] = $profile;
    }
    if (user_access('administer profiles') || $user->uid === $profile->uid && user_access("delete own {$profile->type} profile")) {
      $str_button_value = t('Delete profile');
    }
    if (empty($profile->is_new) && !empty($str_button_value)) {
      $form['actions']['delete'] = array(
        '#type' => 'submit',
        '#value' => $str_button_value,
        '#weight' => 45,
        '#limit_validation_errors' => array(),
        '#submit' => array(
          'profile2_form_submit_own_delete',
        ),
      );
    }

    // Remove user account validate and submit callbacks
    // to stop profile updates also rewriting the user record.
    if (($key = array_search('user_profile_form_validate', $form['#validate'])) !== FALSE) {
      unset($form['#validate'][$key]);
    }
    if (($key = array_search('user_profile_form_submit', $form['#submit'])) !== FALSE) {
      unset($form['#submit'][$key]);
    }

    // Attach the profile edit form.
    profile2_attach_form($form, $form_state);
  }
}