diff --git a/og_forum.module b/og_forum.module index bd49552..bfe874a 100644 --- a/og_forum.module +++ b/og_forum.module @@ -268,6 +268,15 @@ function og_forum_menu() { 'access arguments' => array(1, 2, 'administer forums'), 'file' => 'og_forum.pages.inc', ); + $items['group/%/%/admin/forums/%/delete'] = array( + 'title' => 'Edit forum', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('og_forum_confirm_delete', 1, 2, 5), + 'access callback' => 'og_user_access', + 'access arguments' => array(1, 2, 'administer forums'), + 'file' => 'og_forum.pages.inc', + 'type' => MENU_CALLBACK, + ); } return $items; diff --git a/og_forum.pages.inc b/og_forum.pages.inc index 54cd459..cab7931 100644 --- a/og_forum.pages.inc +++ b/og_forum.pages.inc @@ -233,9 +233,6 @@ function og_forum_form_main($group_type, $gid, $type, $term = NULL) { } $edit = (array) $term; - if ((isset($_POST['op']) && ($_POST['op'] == t('Delete') || $_POST['op'] == t('Move'))) || !empty($_POST['confirm'])) { - return drupal_get_form('og_forum_confirm_delete', $group_type, $gid, $edit['tid']); - } $form = array(); switch ($type) { case 'forum': @@ -302,6 +299,10 @@ function og_forum_form_forum($form, &$form_state, $type, $group_type, $gid, $edi '#type' => 'value', '#value' => $gid, ); + + // Change the delete button submit handler. + $form['actions']['delete']['#submit'] = array('og_forum_form_delete_submit'); + $form['#validate'][] = 'og_forum_form_main_validate'; $form['#submit'][] = 'og_forum_form_main_submit'; @@ -335,89 +336,45 @@ function og_forum_form_main_submit($form, &$form_state) { } /** - * Form constructor for confirming deletion of a forum taxonomy term. + * Form submission handler for og_forum_form_forum(). * - * @param $tid - * ID of the term to be deleted. + * Handles the 'Delete' button on the forum form. + */ +function og_forum_form_delete_submit($form, &$form_state) { + $destination = array(); + if (isset($_GET['destination'])) { + $destination = drupal_get_destination(); + unset($_GET['destination']); + } + $group_type = $form_state['build_info']['args'][1]; + $gid = $form_state['build_info']['args'][2]; + $term = (object) $form_state['build_info']['args'][3]; + $form_state['redirect'] = array('group/' . $group_type . '/' . $gid . '/admin/forums/' . $term->tid . '/delete', array('query' => $destination)); +} + +/** + * Form constructor for confirming deletion of a forum taxonomy term. * * @see forum_confirm_delete_submit() - * @ingroup forms */ function og_forum_confirm_delete($form, &$form_state, $group_type, $gid, $tid) { - $term = taxonomy_term_load($tid); - $nids = taxonomy_select_nodes(array($tid), FALSE); - $topics = node_load_multiple($nids); - foreach ($topics as $nid => $topic) { - // We keep the actual tid in forum table, if it's different from the - // current tid then it means the topic appears in two forums, one of - // them is a shadow copy. - if (isset($topic->forum_tid) && $topic->forum_tid!= $tid) { - unset($topics[$nid]); - } - } - - $question = t('Are you sure you want to delete the forum %name?', array('%name' => $term->name)); - $description = format_plural(count($topics), 'This forum contains 1 topic. Deleting a forum or container will also delete its sub-forums and topics. This action cannot be undone.', 'This forum contains @count topics. Deleting a forum or container will also delete its sub-forums and topics. This action cannot be undone.'); - - $form['tid'] = array('#type' => 'value', '#value' => $tid); - $form['name'] = array('#type' => 'value', '#value' => $term->name); + form_load_include($form_state, 'inc', 'forum', 'forum.admin'); + $form = forum_confirm_delete($form, $form_state, $tid); $form['group_type'] = array('#type' => 'value', '#value' => $group_type); $form['gid'] = array('#type' => 'value', '#value' => $gid); - if (count($topics) > 0) { - // Enable language column if translation module is enabled - // or if we have any node with language. - $multilanguage = (module_exists('translation') || db_query_range("SELECT 1 FROM {node} WHERE language <> ''", 0, 1)->fetchField()); - - // Build topic listing for sortable table - $languages = language_list(); - $topics_checkbox = array(); - foreach ($topics as $topic) { - $topics_checkbox[$topic->nid] = ''; - $options = empty($topic->language) ? array() : array('language' => $languages[$topic->language]); - $form['title'][$topic->nid] = array('#markup' => l($topic->title, 'node/' . $topic->nid, $options) . ' ' . theme('mark', array('type' => node_mark($topic->nid, $topic->changed)))); - $form['username'][$topic->nid] = array('#markup' => format_username($topic)); - $form['status'][$topic->nid] = array('#markup' => ($topic->status ? t('published') : t('not published'))); - $form['changed'][$topic->nid] = array('#markup' => format_date($topic->changed, 'small')); - if ($multilanguage) { - $form['language'][$topic->nid] = array('#markup' => empty($topic->language) ? t('Language neutral') : t($languages[$topic->language]->name)); - } - } - $form['topics'] = array( - '#type' => 'checkboxes', - '#options' => $topics_checkbox, - ); - $form['pager'] = array('#markup' => theme('pager')); - - // Build the 'Move selected topics' form. - $form['move'] = array( - '#type' => 'fieldset', - '#title' => t('Move selected topics'), - '#prefix' => '