Index: modules/contact/contact.admin.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/contact/contact.admin.inc,v retrieving revision 1.9 diff -u -p -r1.9 contact.admin.inc --- modules/contact/contact.admin.inc 25 Mar 2009 13:45:00 -0000 1.9 +++ modules/contact/contact.admin.inc 25 Apr 2009 07:49:37 -0000 @@ -12,7 +12,13 @@ function contact_admin_categories() { $rows = array(); - $header = array(t('Category'), t('Recipients'), t('Selected'), array('data' => t('Operations'), 'colspan' => 2)); + $header = array( + t('Category'), + t('Recipients'), + t('Selected'), + t('Link to form'), + array('data' => t('Operations'), 'colspan' => 2) + ); // Get all the contact categories from the database. $result = db_query('SELECT cid, category, recipients, selected FROM {contact} ORDER BY weight, category'); @@ -23,6 +29,7 @@ function contact_admin_categories() { $record->category, $record->recipients, ($record->selected ? t('Yes') : t('No')), + l(t('contact form'), 'contact/'. $record->cid), l(t('edit'), 'admin/build/contact/edit/' . $record->cid), l(t('delete'), 'admin/build/contact/delete/' . $record->cid), ); @@ -44,6 +51,7 @@ function contact_admin_edit($form_state if (empty($contact) || $op == 'add') { $contact = array( 'category' => '', + 'information' => '', 'recipients' => '', 'reply' => '', 'weight' => 0, @@ -59,6 +67,12 @@ function contact_admin_edit($form_state '#description' => t("Example: 'website feedback' or 'product information'."), '#required' => TRUE, ); + $form['information'] = array('#type' => 'textarea', + '#title' => t('Additional information for this category'), + '#default_value' => $contact['information'], + '#description' => t("Leave empty if you want to use default."), + '#required' => FALSE, + ); $form['recipients'] = array('#type' => 'textarea', '#title' => t('Recipients'), '#default_value' => $contact['recipients'], Index: modules/contact/contact.install =================================================================== RCS file: /cvs/drupal/drupal/modules/contact/contact.install,v retrieving revision 1.11 diff -u -p -r1.11 contact.install --- modules/contact/contact.install 15 Nov 2008 13:01:05 -0000 1.11 +++ modules/contact/contact.install 25 Apr 2009 07:49:37 -0000 @@ -41,6 +41,13 @@ function contact_schema() { 'default' => '', 'description' => 'Category name.', ), + 'information' => array( + 'type' => 'text', + 'not null' => TRUE, + 'size' => 'big', + 'description' => 'Additional information.', + ), + 'recipients' => array( 'type' => 'text', 'not null' => TRUE, @@ -79,3 +86,20 @@ function contact_schema() { return $schema; } + + +/** + * Implementation of hook_update_N(). + */ +function contact_update_7000() { + $ret = array(); + db_add_field($ret, 'contact', 'information', + array( + 'type' => 'text', + 'not null' => TRUE, + 'size' => 'big', + 'description' => 'Additional information.', + 'initial' => '', + )); + return $ret; +} Index: modules/contact/contact.module =================================================================== RCS file: /cvs/drupal/drupal/modules/contact/contact.module,v retrieving revision 1.112 diff -u -p -r1.112 contact.module --- modules/contact/contact.module 8 Mar 2009 05:08:22 -0000 1.112 +++ modules/contact/contact.module 25 Apr 2009 07:49:37 -0000 @@ -99,6 +99,15 @@ function contact_menu() { 'access arguments' => array('access site-wide contact form'), 'type' => MENU_SUGGESTED_ITEM, ); + $items['contact/%contact'] = array( + 'title callback' => 'contact_page_title', + 'title arguments' => array(1), + 'page callback' => 'contact_site_page', + 'page arguments' => array(1), + 'access arguments' => array('access site-wide contact form'), + 'type' => MENU_SUGGESTED_ITEM, + ); + $items['user/%user/contact'] = array( 'title' => 'Contact', 'page callback' => 'contact_user_page', @@ -131,7 +140,7 @@ function _contact_user_tab_access($accou * Load the data for a single contact category. */ function contact_load($cid) { - $contact = db_query("SELECT cid, category, recipients, reply, weight, selected FROM {contact} WHERE cid = :cid", array(':cid' => $cid)) + $contact = db_query("SELECT cid, category, information, recipients, reply, weight, selected FROM {contact} WHERE cid = :cid", array(':cid' => $cid)) ->fetchAssoc(); return empty($contact) ? FALSE : $contact; } @@ -200,3 +209,10 @@ function contact_mail($key, &$message, $ break; } } + +/** + * Set the page title for the contact pages. + */ +function contact_page_title($contact) { + return t('Contact @category', array('@category' => $contact['category'])); +} \ No newline at end of file Index: modules/contact/contact.pages.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/contact/contact.pages.inc,v retrieving revision 1.17 diff -u -p -r1.17 contact.pages.inc --- modules/contact/contact.pages.inc 21 Apr 2009 09:27:52 -0000 1.17 +++ modules/contact/contact.pages.inc 25 Apr 2009 07:49:37 -0000 @@ -9,8 +9,14 @@ /** * Site-wide contact page. + * + * @param $contact + * A keyed array containing the current data of the contact. + * + * @return + * The generated page. */ -function contact_site_page() { +function contact_site_page($contact = array()) { if (!flood_is_allowed('contact', variable_get('contact_hourly_threshold', 3)) && !user_access('administer site-wide contact form')) { $output = t("You cannot send more than %number messages per hour. Please try again later.", array('%number' => variable_get('contact_hourly_threshold', 3))); } @@ -23,17 +29,34 @@ function contact_site_page() { } } else { - $output = drupal_get_form('contact_mail_page'); + $output = drupal_get_form('contact_mail_page', $contact); } return $output; } -function contact_mail_page() { +/** + * Contact form. + * + * @param $form_state + * A keyed array containing the current state of the form. + * @param $contact + * A keyed array containing the current data of the contact. + * @return + * The contact form. + */ +function contact_mail_page($form_state, $contact = array()) { global $user; - $categories = db_query("SELECT cid, category FROM {contact} ORDER BY weight, category")->fetchAllKeyed(); - $default_category = (int) db_query("SELECT cid FROM {contact} WHERE selected = 1")->fetchField(); + if ($contact) { + $categories = array(); + $categories[$contact['cid']] = $contact; + $default_category = $contact['cid']; + } + else { + $categories = db_query("SELECT cid, category FROM {contact} ORDER BY weight, category")->fetchAllKeyed(); + $default_category = (int) db_query("SELECT cid FROM {contact} WHERE selected = 1")->fetchField(); + } // If there is more than one category available and no default category has been selected, // prepend a default placeholder value. @@ -46,9 +69,17 @@ function contact_mail_page() { } } + if ($contact && trim($contact['information']) != '') { + $information = $contact['information']; + } + else { + $information = variable_get('contact_form_information', t('You can leave a message using the contact form below.')); + } + + $form['#token'] = $user->uid ? $user->name . $user->mail : ''; $form['contact_information'] = array( - '#markup' => filter_xss_admin(variable_get('contact_form_information', t('You can leave a message using the contact form below.'))), + '#markup' => filter_xss_admin($information), ); $form['name'] = array( '#type' => 'textfield', Index: modules/contact/contact.test =================================================================== RCS file: /cvs/drupal/drupal/modules/contact/contact.test,v retrieving revision 1.19 diff -u -p -r1.19 contact.test --- modules/contact/contact.test 21 Apr 2009 09:27:52 -0000 1.19 +++ modules/contact/contact.test 25 Apr 2009 07:49:38 -0000 @@ -51,18 +51,18 @@ class ContactSitewideTestCase extends Dr // Test invalid recipients. $invalid_recipients = array('invalid', 'invalid@', 'invalid@site.', '@site.', '@site.com'); foreach ($invalid_recipients as $invalid_recipient) { - $this->addCategory($this->randomName(16), $invalid_recipient, '', FALSE); + $this->addCategory($this->randomName(16), '', $invalid_recipient, '', FALSE); $this->assertRaw(t('%recipient is an invalid e-mail address.', array('%recipient' => $invalid_recipient)), t('Caught invalid recipient (' . $invalid_recipient . ').')); } // Test validation of empty category and recipients fields. - $this->addCategory($category = '', '', '', TRUE); + $this->addCategory($category = '', '', '', '', TRUE); $this->assertText(t('Category field is required.'), t('Caught empty category field')); $this->assertText(t('Recipients field is required.'), t('Caught empty recipients field.')); // Create first valid category. $recipients = array('simpletest@example.com', 'simpletest2@example.com', 'simpletest3@example.com'); - $this->addCategory($category = $this->randomName(16), implode(',', array($recipients[0])), '', TRUE); + $this->addCategory($category = $this->randomName(16), $information = $this->randomName(255), implode(',', array($recipients[0])), '', TRUE); $this->assertRaw(t('Category %category has been added.', array('%category' => $category)), t('Category successfully added.')); // Make sure the newly created category is included in the list of categories. @@ -70,9 +70,10 @@ class ContactSitewideTestCase extends Dr // Test update contact form category. $categories = $this->getCategories(); - $category_id = $this->updateCategory($categories, $category = $this->randomName(16), $recipients_str = implode(',', array($recipients[0], $recipients[1])), $reply = $this->randomName(30), FALSE); - $category_array = db_query("SELECT category, recipients, reply, selected FROM {contact} WHERE cid = :cid", array(':cid' => $category_id))->fetchAssoc(); + $category_id = $this->updateCategory($categories, $category = $this->randomName(16), $information = $this->randomName(255), $recipients_str = implode(',', array($recipients[0], $recipients[1])), $reply = $this->randomName(30), FALSE); + $category_array = db_query("SELECT category, information, recipients, reply, selected FROM {contact} WHERE cid = :cid", array(':cid' => $category_id))->fetchAssoc(); $this->assertEqual($category_array['category'], $category); + $this->assertEqual($category_array['information'], $information); $this->assertEqual($category_array['recipients'], $recipients_str); $this->assertEqual($category_array['reply'], $reply); $this->assertFalse($category_array['selected']); @@ -87,10 +88,10 @@ class ContactSitewideTestCase extends Dr $this->drupalLogin($admin_user); // Add more categories. - $this->addCategory($category = $this->randomName(16), implode(',', array($recipients[0], $recipients[1])), '', FALSE); + $this->addCategory($category = $this->randomName(16), '', implode(',', array($recipients[0], $recipients[1])), '', FALSE); $this->assertRaw(t('Category %category has been added.', array('%category' => $category)), t('Category successfully added.')); - $this->addCategory($category = $this->randomName(16), implode(',', array($recipients[0], $recipients[1], $recipients[2])), '', FALSE); + $this->addCategory($category = $this->randomName(16), '', implode(',', array($recipients[0], $recipients[1], $recipients[2])), '', FALSE); $this->assertRaw(t('Category %category has been added.', array('%category' => $category)), t('Category successfully added.')); // Clear flood table in preparation for flood test and allow other checks to complete. @@ -152,6 +153,21 @@ class ContactSitewideTestCase extends Dr $this->drupalGet('contact'); $this->assertRaw(t('You cannot send more than %number messages per hour. Please try again later.', array('%number' => $edit['contact_hourly_threshold'])), t('Message threshold reached.')); + //Test per category contact form page + $this->drupalLogin($admin_user); + $categories = $this->getCategories(); + $category_id = $this->updateCategory($categories, $category = $this->randomName(16), $information = $this->randomName(255), $recipients_str = implode(',', array($recipients[0], $recipients[1])), $reply = $this->randomName(30), FALSE); + $this->drupalGet('contact/'. $category_id); + //Test infromation + $this->assertText($information, t('Information presents')); + //Test form + $this->assertNoText(t('Category'), t('When view per category contact form page, the category selection element is hidden.')); + + //Test empty information + $category_id = $this->updateCategory($categories, $category = $this->randomName(16), '', $recipients_str = implode(',', array($recipients[0], $recipients[1])), $reply = $this->randomName(30), FALSE); + $this->drupalGet('contact/'. $category_id); + $this->assertText($edit['contact_form_information'], t('Contact information displayed.')); + // Delete created categories. $this->drupalLogin($admin_user); $this->deleteCategories(); @@ -165,9 +181,10 @@ class ContactSitewideTestCase extends Dr * @param string $reply Auto-reply text. * @param boolean $selected Defautly selected. */ - function addCategory($category, $recipients, $reply, $selected) { + function addCategory($category, $information, $recipients, $reply, $selected) { $edit = array(); $edit['category'] = $category; + $edit['information'] = $information; $edit['recipients'] = $recipients; $edit['reply'] = $reply; $edit['selected'] = ($selected ? '1' : '0'); @@ -182,10 +199,11 @@ class ContactSitewideTestCase extends Dr * @param string $reply Auto-reply text. * @param boolean $selected Defautly selected. */ - function updateCategory($categories, $category, $recipients, $reply, $selected) { + function updateCategory($categories, $category, $information, $recipients, $reply, $selected) { $category_id = $categories[array_rand($categories)]; $edit = array(); $edit['category'] = $category; + $edit['information'] = $information; $edit['recipients'] = $recipients; $edit['reply'] = $reply; $edit['selected'] = ($selected ? '1' : '0');