profile2.delete.inc 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. /**
  3. * @file
  4. * Contains functions for Profile Delete.
  5. */
  6. /**
  7. * Confirm form for deleting own profile.
  8. */
  9. function profile2_delete_confirm_form($form, &$form_state, $profile) {
  10. global $user;
  11. if (isset($profile) && is_object($profile)) {
  12. $form_state += array('profile2' => $profile);
  13. if ($user->uid === $profile->uid) {
  14. $confirm_question = t('Are you sure you want to delete your own %label profile ?', array('%label' => $profile->label));
  15. }
  16. elseif (user_access('administer profiles')) {
  17. $user_account = user_load($profile->uid);
  18. if (!empty($user_account)) {
  19. $confirm_question = t("Are you sure you want to delete profile %label of user %user?", array('%label' => $profile->label, '%user' => $user_account->name));
  20. }
  21. }
  22. return confirm_form($form, $confirm_question, 'user/' . $profile->uid);
  23. }
  24. }
  25. /**
  26. * Confirm form submit for deleting own profile.
  27. */
  28. function profile2_delete_confirm_form_submit($form, &$form_state) {
  29. $profile = isset($form_state['profile2']) ? $form_state['profile2'] : '';
  30. if (isset($profile) && is_object($profile)) {
  31. $profile->delete();
  32. drupal_set_message(t('Deleted %label.', array('%label' => $profile->label)));
  33. }
  34. $form_state['redirect'] = 'user/' . $profile->uid;
  35. }