You are here

function og_node_delete_confirm_submit in Organic groups 6.2

Same name and namespace in other branches
  1. 5.8 og.module \og_node_delete_confirm_submit()
  2. 5 og.module \og_node_delete_confirm_submit()
  3. 5.2 og.module \og_node_delete_confirm_submit()
  4. 5.3 og.module \og_node_delete_confirm_submit()
  5. 5.7 og.module \og_node_delete_confirm_submit()
  6. 6 og.module \og_node_delete_confirm_submit()

Submit handler for node delete form. Handles deletes to group nodes.

1 string reference to 'og_node_delete_confirm_submit'
og_node_delete_group_form in ./og.module
Form alter the node delete form for a group.

File

./og.module, line 1963
Code for the Organic Groups module.

Code

function og_node_delete_confirm_submit($form, &$form_state) {
  $deleted_group_nid = $form_state['values']['nid'];
  $target_group_nid = $form_state['values']['target'];
  $delete_orphans = $form_state['values']['verb'] == OG_DELETE_ORPHANS;
  $move_children = $form_state['values']['verb'] >= OG_DELETE_MOVE_NODES;
  $count = 0;
  foreach (og_group_child_nids($deleted_group_nid) as $child_nid) {
    $node = node_load($child_nid);
    unset($node->og_groups[$deleted_group_nid]);
    if ($move_children) {

      // there is an array_unique() in og_save_ancestry which guards against duplicates so don't worry here.
      $node->og_groups[$target_group_nid] = $target_group_nid;
    }
    if ($delete_orphans && count($node->og_groups) == 0) {
      node_delete($node->nid);
    }
    else {
      node_save($node);
    }
    $count++;
  }
  if ($delete_orphans) {
    drupal_set_message(format_plural($count, 'Deleted 1 orphan post.', 'Deleted @count orphan posts.'));
  }
  elseif ($move_children) {
    drupal_set_message(format_plural($count, 'Moved 1 orphan post.', 'Moved @count orphan posts.'));
  }
  if ($move_children) {
    $form_state['redirect'] = 'node/' . $target_group_nid;
  }
}