diff --git a/core/modules/contact/contact.admin.inc b/core/modules/contact/contact.admin.inc index 9fde037..bc9ec2c 100644 --- a/core/modules/contact/contact.admin.inc +++ b/core/modules/contact/contact.admin.inc @@ -13,6 +13,7 @@ function contact_category_list() { t('Category'), t('Recipients'), t('Selected'), + t('Link to form'), array('data' => t('Operations'), 'colspan' => 2), ); $rows = array(); @@ -32,6 +33,7 @@ function contact_category_list() { check_plain($category->category), check_plain($category->recipients), ($category->selected ? t('Yes') : t('No')), + l(t('contact form'), 'contact/'. $category->cid), l(t('Edit'), 'admin/structure/contact/edit/' . $category->cid), l(t('Delete'), 'admin/structure/contact/delete/' . $category->cid), ); diff --git a/core/modules/contact/contact.module b/core/modules/contact/contact.module index 9388877..fb161a8 100644 --- a/core/modules/contact/contact.module +++ b/core/modules/contact/contact.module @@ -93,6 +93,15 @@ function contact_menu() { 'type' => MENU_SUGGESTED_ITEM, 'file' => 'contact.pages.inc', ); + $items['contact/%contact'] = array( + 'title callback' => 'contact_page_title', + 'title arguments' => array(1), + 'page callback' => 'drupal_get_form', + 'page arguments' => array('contact_site_form', 1), + 'access arguments' => array('access site-wide contact form'), + 'type' => MENU_SUGGESTED_ITEM, + 'file' => 'contact.pages.inc', + ); $items['user/%user/contact'] = array( 'title' => 'Contact', 'page callback' => 'drupal_get_form', @@ -253,3 +262,10 @@ function contact_form_user_admin_settings_alter(&$form, &$form_state) { '#default_value' => variable_get('contact_default_status', 1), ); } + +/** + * Sets the page title for the contact pages. + */ +function contact_page_title($contact) { + return t('Contact @category', array('@category' => $contact['category'])); +} diff --git a/core/modules/contact/contact.pages.inc b/core/modules/contact/contact.pages.inc index 30b2825..d9e775e 100644 --- a/core/modules/contact/contact.pages.inc +++ b/core/modules/contact/contact.pages.inc @@ -8,10 +8,15 @@ /** * Form builder; the site-wide contact form. * + * @param $category + * (optional) An associative array containing the current data for the category: + * - cid: The category ID + * - category: The name of the category + * * @see contact_site_form_validate() * @see contact_site_form_submit() */ -function contact_site_form($form, &$form_state) { +function contact_site_form($form, &$form_state, $category = array()) { global $user; // Check if flood control has been activated for sending e-mails. @@ -23,16 +28,23 @@ function contact_site_form($form, &$form_state) { drupal_exit(); } - // Get an array of the categories and the current default category. - $categories = db_select('contact', 'c') - ->addTag('translatable') - ->fields('c', array('cid', 'category')) - ->orderBy('weight') - ->orderBy('category') - ->execute() - ->fetchAllKeyed(); - $default_category = db_query("SELECT cid FROM {contact} WHERE selected = 1")->fetchField(); - + if ($category) { + // If the function got the $category then the $categories array contains only that. + $categories = array(); + $categories[$category['cid']] = $category; + $default_category = $category['cid']; + } + else { + // Get an array of the categories and the current default category. + $categories = db_select('contact', 'c') + ->addTag('translatable') + ->fields('c', array('cid', 'category')) + ->orderBy('weight') + ->orderBy('category') + ->execute() + ->fetchAllKeyed(); + $default_category = db_query("SELECT cid FROM {contact} WHERE selected = 1")->fetchField(); + } // If there are no categories, do not display the form. if (!$categories) { if (user_access('administer contact forms')) { diff --git a/core/modules/contact/contact.test b/core/modules/contact/contact.test index 129eb30..48ddb97 100644 --- a/core/modules/contact/contact.test +++ b/core/modules/contact/contact.test @@ -1,7 +1,7 @@ assertResponse(403, t('Access denied to anonymous user after reaching message treshold.')); $this->assertRaw(t('You cannot send more than %number messages in @interval. Try again later.', array('%number' => variable_get('contact_threshold_limit', 3), '@interval' => format_interval(600))), t('Message threshold reached.')); + // Test per category contact form page + $this->drupalLogin($admin_user); + $categories = $this->getCategories(); + $category = $this->randomName(16); + $recipients_str = implode(',', array($recipients[0], $recipients[1])); + $reply = $this->randomName(30); + $category_id = $this->updateCategory($categories, $category, $recipients_str, $reply, FALSE); + $this->drupalGet('contact/'. $category_id); + // Test infromation + $this->assertText($category, t('Category presents')); + // Test form + $this->assertNoText(t('Category'), t('The category select is hidden in the per category contact form page.')); + // Delete created categories. $this->drupalLogin($admin_user); $this->deleteCategories();