diff options
Diffstat (limited to 'modules/forum')
-rw-r--r-- | modules/forum/forum.module | 52 | ||||
-rw-r--r-- | modules/forum/forum.test | 28 |
2 files changed, 60 insertions, 20 deletions
diff --git a/modules/forum/forum.module b/modules/forum/forum.module index 1947e4d05..eddac7978 100644 --- a/modules/forum/forum.module +++ b/modules/forum/forum.module @@ -23,7 +23,7 @@ function forum_help($path, $arg) { $output .= '</ul>'; $output .= '</ul>'; $output .= '</ul>'; - $output .= '<p>' . t('For more information, see the online handbook entry for <a href="@forum">Forum module</a>.', array('@forum' => 'http://drupal.org/handbook/modules/forum')) . '</p>'; + $output .= '<p>' . t('For more information, see the online handbook entry for <a href="@forum">Forum module</a>.', array('@forum' => 'http://drupal.org/documentation/modules/forum')) . '</p>'; $output .= '<h3>' . t('Uses') . '</h3>'; $output .= '<dl>'; $output .= '<dt>' . t('Setting up forum structure') . '</dt>'; @@ -468,10 +468,10 @@ function forum_permission() { /** * Implements hook_taxonomy_term_delete(). */ -function forum_taxonomy_term_delete($tid) { +function forum_taxonomy_term_delete($term) { // For containers, remove the tid from the forum_containers variable. $containers = variable_get('forum_containers', array()); - $key = array_search($tid, $containers); + $key = array_search($term->tid, $containers); if ($key !== FALSE) { unset($containers[$key]); } @@ -586,26 +586,40 @@ function forum_field_storage_pre_update($entity_type, $entity, &$skip_fields) { } /** - * Implements hook_form_alter(). + * Implements hook_form_FORM_ID_alter() for taxonomy_form_vocabulary(). */ -function forum_form_alter(&$form, $form_state, $form_id) { +function forum_form_taxonomy_form_vocabulary_alter(&$form, &$form_state, $form_id) { $vid = variable_get('forum_nav_vocabulary', 0); if (isset($form['vid']['#value']) && $form['vid']['#value'] == $vid) { - // Hide critical options from forum vocabulary. - if ($form_id == 'taxonomy_form_vocabulary') { - $form['help_forum_vocab'] = array( - '#markup' => t('This is the designated forum vocabulary. Some of the normal vocabulary options have been removed.'), - '#weight' => -1, - ); - $form['hierarchy'] = array('#type' => 'value', '#value' => 1); - $form['delete']['#access'] = FALSE; - } + $form['help_forum_vocab'] = array( + '#markup' => t('This is the designated forum vocabulary. Some of the normal vocabulary options have been removed.'), + '#weight' => -1, + ); + // Forum's vocabulary always has single hierarchy. Forums and containers + // have only one parent or no parent for root items. By default this value + // is 0. + $form['hierarchy']['#value'] = 1; + // Do not allow to delete forum's vocabulary. + $form['actions']['delete']['#access'] = FALSE; + } +} + +/** + * Implements hook_form_FORM_ID_alter() for taxonomy_form_term(). + */ +function forum_form_taxonomy_form_term_alter(&$form, &$form_state, $form_id) { + $vid = variable_get('forum_nav_vocabulary', 0); + if (isset($form['vid']['#value']) && $form['vid']['#value'] == $vid) { // Hide multiple parents select from forum terms. - elseif ($form_id == 'taxonomy_form_term') { - $form['advanced']['parent']['#access'] = FALSE; - } + $form['relations']['parent']['#access'] = FALSE; } - if (!empty($form['#node_edit_form']) && isset($form['taxonomy_forums'])) { +} + +/** + * Implements hook_form_BASE_FORM_ID_alter() for node_form(). + */ +function forum_form_node_form_alter(&$form, &$form_state, $form_id) { + if (isset($form['taxonomy_forums'])) { $langcode = $form['taxonomy_forums']['#language']; // Make the vocabulary required for 'real' forum-nodes. $form['taxonomy_forums'][$langcode]['#required'] = TRUE; @@ -784,7 +798,7 @@ function forum_forum_load($tid = NULL) { $query->addExpression('SUM(ncs.comment_count)', 'comment_count'); $counts = $query ->fields('f', array('tid')) - ->condition('status', 1) + ->condition('n.status', 1) ->groupBy('tid') ->addTag('node_access') ->execute() diff --git a/modules/forum/forum.test b/modules/forum/forum.test index cb9beffc3..612b09cff 100644 --- a/modules/forum/forum.test +++ b/modules/forum/forum.test @@ -242,10 +242,31 @@ class ForumTestCase extends DrupalWebTestCase { // Save forum overview. $this->drupalPost('admin/structure/forum/', array(), t('Save')); $this->assertRaw(t('The configuration options have been saved.')); - // Delete this second form. + // Delete this second forum. $this->deleteForum($this->delete_forum['tid']); // Create forum at the top (root) level. $this->root_forum = $this->createForum('forum'); + + // Test vocabulary form alterations. + $this->drupalGet('admin/structure/taxonomy/forums/edit'); + $this->assertFieldByName('op', t('Save'), 'Save button found.'); + $this->assertNoFieldByName('op', t('Delete'), 'Delete button not found.'); + + // Test term edit form alterations. + $this->drupalGet('taxonomy/term/' . $this->container['tid'] . '/edit'); + // Test parent field been hidden by forum module. + $this->assertNoField('parent[]', 'Parent field not found.'); + + // Test tags vocabulary form is not affected. + $this->drupalGet('admin/structure/taxonomy/tags/edit'); + $this->assertFieldByName('op', t('Save'), 'Save button found.'); + $this->assertFieldByName('op', t('Delete'), 'Delete button found.'); + // Test tags vocabulary term form is not affected. + $this->drupalGet('admin/structure/taxonomy/tags/add'); + $this->assertField('parent[]', 'Parent field found.'); + // Test relations fieldset exists. + $relations_fieldset = $this->xpath("//fieldset[@id='edit-relations']"); + $this->assertTrue(isset($relations_fieldset[0]), 'Relations fieldset element found.'); } /** @@ -341,6 +362,11 @@ class ForumTestCase extends DrupalWebTestCase { // Assert that the forum no longer exists. $this->drupalGet('forum/' . $tid); $this->assertResponse(404, 'The forum was not found'); + + // Assert that the associated term has been removed from the + // forum_containers variable. + $containers = variable_get('forum_containers', array()); + $this->assertFalse(in_array($tid, $containers), 'The forum_containers variable has been updated.'); } /** |