You are here

function profile2_revision_delete_confirm_submit in Profile 2 7.2

File

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

Code

function profile2_revision_delete_confirm_submit($form, &$form_state) {
  $profile_revision = $form['#profile_revision'];
  $deleted = entity_revision_delete('profile2', $profile_revision->vid);
  if ($deleted) {
    drupal_set_message(t('@type profile revision from %date has been deleted.', array(
      '@type' => $profile_revision->type,
      '%date' => format_date($profile_revision->revision_timestamp),
    )));
  }
  else {
    drupal_set_message(t('Error occured while deleting revision.'), 'error');
  }
  $redirect = _profile2_revision_base_path($profile_revision);

  // If deleting the last revision, re-directing to the revisions page will result in
  // an access denied error, so in this case re-direct to the profile view.
  if (db_select('profile_revision', 'pr')
    ->condition('pr.pid', $profile_revision->pid)
    ->countQuery()
    ->execute()
    ->fetchField() < 2) {
    $redirect = str_replace('/revisions', '', $redirect);
  }
  $form_state['redirect'] = $redirect;
}