diff --git a/modules/contact/contact.admin.inc b/modules/contact/contact.admin.inc index 9fde037..bc9ec2c 100644 --- a/modules/contact/contact.admin.inc +++ b/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/modules/contact/contact.module b/modules/contact/contact.module index eaae9c6..03f4ca7 100644 --- a/modules/contact/contact.module +++ b/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', @@ -255,3 +264,10 @@ function contact_form_user_admin_settings_alter(&$form, &$form_state) { '#default_value' => variable_get('contact_default_status', 1), ); } + +/** + * Set the page title for the contact pages. + */ +function contact_page_title($contact) { + return t('Contact @category', array('@category' => $contact['category'])); +} diff --git a/modules/contact/contact.pages.inc b/modules/contact/contact.pages.inc index 30b2825..92ab2d3 100644 --- a/modules/contact/contact.pages.inc +++ b/modules/contact/contact.pages.inc @@ -8,10 +8,13 @@ /** * Form builder; the site-wide contact form. * + * @param $contact + * A keyed array containing the current data of the contact. + * * @see contact_site_form_validate() * @see contact_site_form_submit() */ -function contact_site_form($form, &$form_state) { +function contact_site_form($form, &$form_state, $contact = array()) { global $user; // Check if flood control has been activated for sending e-mails. @@ -23,16 +26,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 ($contact) { + // Set an array of the categories if set $contact array. + $categories = array(); + $categories[$contact['cid']] = $contact; + $default_category = $contact['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/modules/contact/contact.test b/modules/contact/contact.test index 129eb30..6c55812 100644 --- a/modules/contact/contact.test +++ b/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_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); + //Test infromation + $this->assertText($category, t('Category presents')); + //Test form + $this->assertNoText(t('Category'), t('When view per category contact form page, the category selection element is hidden.')); + // Delete created categories. $this->drupalLogin($admin_user); $this->deleteCategories();