'Settings', 'page callback' => 'drupal_get_form', 'page arguments' => array('contact_forms_settings'), 'access arguments' => array('access site-wide contact form'), 'type' => MENU_NORMAL_ITEM, ); return $items; } /** * Implementation of hook_help */ function contact_forms_help($path, $arg) { switch ($path) { case 'admin/help#contact_forms': $output = ''; $output .= '

' . t('About') . '

'; $output .= '

' . t('The Contact Forms module adds the following features to the Site Wide Contact Form generated by the core contact module.') . '

'; $output .= '

' . t('Uses') . '

'; $output .= '
'; $output .= '
' . t('Site-wide contact forms') . '
'; $output .= '
' . t('The Contact page provides a simple form for users with the Use the site-wide contact form permission to send comments, feedback, or other requests. You can create categories for directing the contact form messages to a set of defined recipients. Common categories for a business site, for example, might include "Website feedback" (messages are forwarded to website administrators) and "Product information" (messages are forwarded to members of the sales department). E-mail addresses defined within a category are not displayed publicly.', array('@contact' => url('contact'))) . '

'; $output .= '
'; return $output; case 'admin/structure/contact/settings': $output = ''; $output .= '

' . t('The Contact Forms module creates unique contact forms for each contact category with a unique path. Here you can set the default title and header which will be used if they are not specified on the category edit page.') . '

'; $output .= '

' . t('More help can be found at Contact Forms help page.', array('@help' => url('admin/help/contact_forms'))) . '

'; return $output; case 'admin/structure/contact/edit/%': $output = ''; $output .= '

' . t('Help can be found at Contact Forms help page.', array('@help' => url('admin/help/contact_forms'))) . '

'; return $output; case 'admin/structure/contact': $output = '

' . t('Features added by Contact Forms Module.') . '

' . t('Now that you have the Contact Forms module enabled you can add a unique title and additional text to each category on it\'s edit page or a global title and additional information on the Contact Forms settings page.', array('@settings' => url('admin/structure/contact/settings'))) . '

'; return $output; } } /** * Implementation of hook_settings */ function contact_forms_settings($form, &$form_state){ drupal_set_title(t('Contact Forms Settings')); $form['contact_form_redirect'] = array( '#type' => 'textfield', '#title' => t('Contact Form redirect'), '#default_value' => variable_get('contactform_redirect', 'contact'), '#weight' => -3, '#maxlength' => 60, '#description' => t('The page you would like to redirect to if a contact/category path is entered that doesn\'t exist.'), '#required' => false, ); $form['contact_forms_title'] = array( '#type' => 'textfield', '#title' => t('Default Title for individual contact pages'), '#default_value' => variable_get('contactform_title', 'Contact @category'), '#weight' => -2, '#maxlength' => 60, '#description' => t('If a category doesn\'t have a page title specified this will be shown. To place the category name in the title use the wildcard "@category".'), '#required' => true, ); $form['contact_forms_information'] = array( '#type' => 'textarea', '#title' => t('Default Additional Information for individual contact pages'), '#weight' => -1, '#default_value' => variable_get('contactforms_information', t('You can send @category a message using the contact form below.')), '#description' => t('If a category doesn\'t have additional information specified this will be shown. To place the category name in your message use the wildcard "@category" e.g. You can send @category a message using the contact form below.'), ); return system_settings_form($form); } /** * Implementation of hook_form_alter() */ function contact_forms_form_alter(&$form, $form_state, $form_id) { $path = $_GET['q']; // redirect contact if another fall back page is defined if ($path == 'contact' && variable_get('contactform_redirect', 'contact') != 'contact') { drupal_goto(variable_get('contactform_redirect', 'contact')); } // Alter all contact forms except for /contact if ($form_id == 'contact_site_form' && $path != 'contact') { $category = str_replace( array('-','_') , ' ' , arg(1)); $categories_data = db_query("SELECT * FROM {contact} WHERE LOWER(category) = LOWER(:category)", array(':category' => $category,))->fetchObject(); // if category doesn't exist redirect to 'contact' or User Defined Page if (!$categories_data) { drupal_goto(variable_get('contactform_redirect', 'contact')); } // Set Contact Form Title $contact_form_title = (!$categories_data->page_title) ? variable_get('contactform_title', 'Contact @category') : $categories_data->page_title ; $contact_form_title = str_replace( '@category', $categories_data->category, $contact_form_title); drupal_set_title(check_plain($contact_form_title)); // Get Additional Info $additional_info = (!$categories_data->page_info) ? variable_get('contactforms_information' , 'You can send @category a message using the contact form below.') : $categories_data->page_info ; $additional_info = str_replace( '@category', $categories_data->category, $additional_info); $form['contact_information'] = array( '#markup' => filter_xss_admin($additional_info), '#weight' => -1, ); $subject = str_replace( array('-','_') , ' ' , arg(2)); $form['subject'] = array('#type' => 'textfield', '#title' => t('Subject'), '#maxlength' => 255, '#default_value' => $subject, '#required' => TRUE, ); $form['cid'] = array( '#type' => 'hidden', '#value' => $categories_data->cid, '#required' => TRUE, ); } /** * Alter the contact_category_edit_form */ if($form_id == 'contact_category_edit_form'){ $cid = $form['cid']['#value']; if ($cid) { $query = db_query('SELECT * FROM {contact} WHERE cid = :cid', array(':cid' => $cid,)); $contact = $query->fetch(); } // Adds a text field that will hold category specific info for the contact page information $form['page_title'] = array( '#type' => 'textfield', '#title' => t('Page Title'), '#weight' => -1, '#default_value' => $contact->page_title, '#description' => t('Page Title for this individual contact page. If this is left empty the "Default Page Title" will be displayed'), ); // Adds a text area that will hold category specific info for the contact page information $form['page_info'] = array( '#type' => 'textarea', '#title' => t('Additional Information'), '#weight' => 0, '#default_value' => $contact->page_info, '#description' => t('Information to show on the individual contact page. If this is left empty the "Default Additional Information" will be displayed'), ); // Set the weight of the category name so It appears above our inserted info area $form['category']['#weight']='-2'; } } /** * Implementation of hook_menu_alter */ function contact_forms_menu_alter(&$items) { $items['contact/%'] = $items['contact']; $items['admin/structure/contact'] = array( 'title' => 'Contact form', 'description' => 'Create a system contact form and set up categories for the form to use.', 'page callback' => 'contact_forms_category_list', 'access arguments' => array('administer contact forms'), ); } /** * Categories/list tab. */ function contact_forms_category_list() { $header = array( t('Category'), t('Recipients'), t('Selected'), t('Title'), t('Info'), array('data' => t('Operations'), 'colspan' => 2), ); $rows = array(); // Get all the contact categories from the database. $categories = db_query('SELECT cid, category, recipients, selected, page_title, page_info FROM {contact} ORDER BY weight, category')->fetchAll(); // Loop through the categories and add them to the table. foreach ($categories as $category) { $title_status = ($category->page_title!='') ? 'Custom' : 'Default'; $info_status = ($category->page_info!='') ? 'Custom' : 'Default'; $rows[] = array( check_plain($category->category), check_plain($category->recipients), ($category->selected ? t('Yes') : t('No')), $title_status, $info_status, l(t('Edit'), 'admin/structure/contact/edit/' . $category->cid), l(t('Delete'), 'admin/structure/contact/delete/' . $category->cid), ); } if (!$rows) { $rows[] = array(array( 'data' => t('No categories available.'), 'colspan' => 7, )); } return theme('table', array('header' => $header, 'rows' => $rows)); } /** * Implementation of hook_schema_alter */ function contact_forms_schema_alter(&$schema) { // Add field to existing schema. $schema['contact']['fields']['page_title'] = array( 'type' => 'text', 'not null' => FALSE, 'size' => 'normal', 'description' => 'Page Title displayed on the individual contact form pages', ); $schema['contact']['fields']['page_info'] = array( 'type' => 'text', 'not null' => FALSE, 'size' => 'big', 'description' => 'Category Page Information Displayed on the individual contact form pages', ); }