diff --git a/modules/forum/forum.admin.inc b/modules/forum/forum.admin.inc index 8b85ffa..9f6bb4a 100644 --- a/modules/forum/forum.admin.inc +++ b/modules/forum/forum.admin.inc @@ -207,7 +207,7 @@ function forum_form_container($form, &$form_state, $edit = array()) { */ function forum_confirm_delete($form, &$form_state, $tid) { $term = taxonomy_term_load($tid); - $nids = taxonomy_select_nodes(array($tid), 'or', 'all'); + $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 @@ -232,30 +232,14 @@ function forum_confirm_delete($form, &$form_state, $tid) { // 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 the sortable table header. - $header = array(); - $header[] = theme('table_select_header_cell'); - $header[] = array('data' => t('Title'), 'field' => 'n.title'); - $header[] = array('data' => t('Author'), 'field' => 'u.name'); - $header[] = array('data' => t('Status'), 'field' => 'n.status'); - $header[] = array('data' => t('Updated'), 'field' => 'n.changed', 'sort' => 'desc'); - if ($multilanguage) { - $header[] = array('data' => t('Language'), 'field' => 'n.language'); - } - - $form['header'] = array( - '#type' => 'value', - '#value' => $header, - ); - // 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', node_mark($topic->nid, $topic->changed))); - $form['username'][$topic->nid] = array('#markup' => theme('username', $topic)); + $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) { @@ -266,7 +250,7 @@ function forum_confirm_delete($form, &$form_state, $tid) { '#type' => 'checkboxes', '#options' => $topics_checkbox, ); - $form['pager'] = array('#markup' => theme('pager', NULL)); + $form['pager'] = array('#markup' => theme('pager')); // Build the 'Move selected topics' form. $form['move'] = array( @@ -276,32 +260,27 @@ function forum_confirm_delete($form, &$form_state, $tid) { '#suffix' => '', ); // Get a drop-down menu of other forum/containers to move topics. - $other_forums = taxonomy_form(variable_get('forum_nav_vocabulary', '')); - foreach ($other_forums['#options'] as $option_id => $option) { - if (isset($option->option[$tid])) { - unset($other_forums['#options'][$option_id]); - break; - } - } + $dst_element = _forum_parent_select($tid, t('Move topics to'), 'forum'); // Enable the 'Move selected topics' form only if there are other forums/containers. - if (count($other_forums['#options']) > 1) { - $form['move']['tid_dst'] = $other_forums; + if (count($dst_element['#options']) > 1) { + unset($dst_element['#options'][0]); + $form['move']['tid_dst'] = $dst_element; $form['move']['submit'] = array( '#type' => 'submit', '#value' => t('Move'), + '#validate' => array('forum_confirm_delete_move_validate'), '#submit' => array('forum_confirm_delete_move_submit'), ); } else { // If there are no destinations, disable 'Move selected topics' form and remove table checkboxes. $form['move']['no_dst'] = array('#markup' => t('There are no other forums to move these topics.')); - array_shift($form['header']['#value']); unset($form['topics']); } } - $form['#theme'] = 'forum_confirm_delete'; $form = confirm_form($form, t('Are you sure you want to delete the forum %name?', array('%name' => $term->name)), 'admin/structure/forum', t('Deleting a forum or container will also delete its sub-forums, if any. To delete posts in this forum, visit content administration first. This action cannot be undone.', array('@content' => url('admin/content'))), t('Delete')); + $form['#theme'] = 'forum_confirm_delete'; return $form; } @@ -310,7 +289,7 @@ function forum_confirm_delete($form, &$form_state, $tid) { */ function forum_confirm_delete_submit($form, &$form_state) { $tid = $form_state['values']['tid']; - $nids = taxonomy_select_nodes(array($tid), 'or', 'all'); + $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 @@ -338,6 +317,19 @@ function forum_confirm_delete_submit($form, &$form_state) { * * Execute the chosen 'Move location options' on the selected topics. */ +function forum_confirm_delete_move_validate($form, &$form_state) { + $tid_dst = $form_state['values']['tid_dst']; + $term_dst = forum_forum_load($tid_dst); + if ($term_dst->container) { + form_set_error('move][tid_dst', t('The item %name is a forum container, not a forum. Select one of the forums below instead.', array('%name' => $term_dst->name))); + } +} + +/** + * Process forum delete confirmation move submissions. + * + * Execute the chosen 'Move location options' on the selected topics. + */ function forum_confirm_delete_move_submit($form, &$form_state) { $tid_src = $form_state['values']['tid']; $tid_dst = $form_state['values']['tid_dst']; @@ -345,13 +337,12 @@ function forum_confirm_delete_move_submit($form, &$form_state) { $topics = array_filter($form_state['values']['topics']); if (!empty($topics) && $tid_dst) { $topics = node_load_multiple($topics); - $term_dst = taxonomy_term_load($tid_dst); + foreach ($topics as $topic) { $topic->tid = $tid_dst; $topic->forum_tid = $tid_dst; - $topic->taxonomy[$tid_dst] = $term_dst; - module_invoke_all('node_presave', $topic, array($tid_dst)); - module_invoke_all('node_update', $topic, array($tid_dst)); + $topic->taxonomy_forums[LANGUAGE_NONE][0]['tid'] = $tid_dst; + node_save($topic); } } // Return to the forum_confirm_delete form with these topics now deleted. @@ -363,12 +354,26 @@ function forum_confirm_delete_move_submit($form, &$form_state) { * * @ingroup themeable */ -function theme_forum_confirm_delete($form) { +function theme_forum_confirm_delete($variables) { + $form = $variables['form']; $output = ''; if (isset($form['move'])) { $output .= drupal_render($form['move']); - $header = $form['header']['#value']; + + // Multilingual column + $multilanguage = isset($form['language']); + + // Build the sortable table header. + $header = array(); + $header[] = theme('table_select_header_cell'); + $header[] = array('data' => t('Title'), 'field' => 'n.title'); + $header[] = array('data' => t('Author'), 'field' => 'u.name'); + $header[] = array('data' => t('Status'), 'field' => 'n.status'); + $header[] = array('data' => t('Updated'), 'field' => 'n.changed', 'sort' => 'desc'); + if ($multilanguage) { + $header[] = array('data' => t('Language'), 'field' => 'n.language'); + } $has_topics = isset($form['title']) && is_array($form['title']); if ($has_topics) { @@ -382,7 +387,7 @@ function theme_forum_confirm_delete($form) { $row[] = drupal_render($form['username'][$key]); $row[] = drupal_render($form['status'][$key]); $row[] = drupal_render($form['changed'][$key]); - if (isset($form['language'])) { + if ($multilanguage) { $row[] = drupal_render($form['language'][$key]); } $rows[] = $row; @@ -394,7 +399,7 @@ function theme_forum_confirm_delete($form) { ); } - $output .= theme('table', $header, $rows); + $output .= theme('table', array('header' => $header, 'rows' => $rows)); if ($form['pager']['#markup']) { $output .= drupal_render($form['pager']);