From eddf678f1f2f81784bbe968647c3ead4fdc8eedb Mon Sep 17 00:00:00 2001
From: pramod <pramod@2473980.no-reply.drupal.org>
Date: Fri, 2 Dec 2016 12:09:18 +0530
Subject: [PATCH] Issue #2831104 by reszli, pramod_patil: Ability to alter the
 submit button label

---
 contact_plus.module | 71 ++++++++++++++++++++++++++++++-----------------------
 1 file changed, 40 insertions(+), 31 deletions(-)

diff --git a/contact_plus.module b/contact_plus.module
index 6400589..1c9416e 100644
--- a/contact_plus.module
+++ b/contact_plus.module
@@ -1,7 +1,8 @@
 <?php
+
 /**
  * @file
- * Adds redirection paths and custom config to the core contact module
+ * Adds redirection paths and custom config to the core contact module.
  */
 
 /**
@@ -10,7 +11,7 @@
 function contact_plus_menu() {
   // Make a new menu item to serve as default tab.
   // This inherits the parent menu item properties (not otherwise set).
-  // This line is an OVERRIDE of an existing menu item
+  // This line is an OVERRIDE of an existing menu item.
   $items['admin/structure/contact/categories'] = array(
     'title' => 'Categories',
     'type' => MENU_DEFAULT_LOCAL_TASK,
@@ -44,7 +45,6 @@ function contact_plus_menu() {
   return $items;
 }
 
-
 /**
  * Create the system settings form for the sitewide contact form.
  */
@@ -119,10 +119,17 @@ function contact_plus_site_form($form, &$form_state) {
     '#default_value' => variable_get('contact_plus_site_copy', FALSE),
   );
 
+  // Change send button label.
+  $form['contact_plus_submit_button'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Submit button label'),
+    '#description' => t('Change the Send message button label.'),
+    '#default_value' => variable_get('contact_plus_submit_button', 'Send message'),
+  );
+
   return system_settings_form($form);
 }
 
-
 /**
  * Create the system settings form for the user contact form.
  */
@@ -168,7 +175,7 @@ function contact_plus_user_form($form, &$form_state) {
     '#weight' => '-2',
   );
 
-  // if the token module exists then provide global token support
+  // If the token module exists then provide global token support.
   if (module_exists('token')) {
     $form['token_help'] = array(
       '#theme' => 'token_tree',
@@ -236,12 +243,11 @@ function contact_plus_user_form($form, &$form_state) {
   return system_settings_form($form);
 }
 
-
 /**
  * Implements hook_form_FORM_ID_alter().
  */
 function contact_plus_form_contact_site_form_alter(&$form, &$form_state, $form_id) {
-  // Sets the page title if it is configured
+  // Sets the page title if it is configured.
   $title = variable_get('contact_plus_site_title', '');
   if ($title !== '') {
     drupal_set_title($title);
@@ -305,16 +311,18 @@ function contact_plus_form_contact_site_form_alter(&$form, &$form_state, $form_i
     $form['copy']['#access'] = FALSE;
   }
 
+  // Change submit button label.
+  $form['actions']['submit']['#value'] = variable_get('contact_plus_submit_button', 'Send message');
+
   // Add a submit handler so we can perform the redirect on submit.
   $form['#submit'][] = 'contact_plus_submit_site_contact';
 }
 
-
 /**
  * Implements hook_form_FORM_ID_alter().
  */
 function contact_plus_form_contact_personal_form_alter(&$form, &$form_state, $form_id) {
-  // Sets the page title if it is configured
+  // Sets the page title if it is configured.
   $title = variable_get('contact_plus_user_title', '');
 
   if ($title !== '') {
@@ -322,7 +330,7 @@ function contact_plus_form_contact_personal_form_alter(&$form, &$form_state, $fo
      * Omitting token support for now as it seems spurious
     // if the token module exists then replace any tokens in the path
     if (module_exists('token')) {
-      $title = token_replace($title);
+    $title = token_replace($title);
     }
      */
     drupal_set_title($title);
@@ -334,7 +342,7 @@ function contact_plus_form_contact_personal_form_alter(&$form, &$form_state, $fo
     $text_user = check_markup($text_array['value'], $text_array['format'], '', TRUE);
     $form['contact_plus_user_text'] = array(
       '#markup' => $text_user,
-      // if we want to move the message down, alter this.
+      // If we want to move the message down, alter this.
       '#weight' => -10,
     );
   }
@@ -384,7 +392,7 @@ function contact_plus_form_contact_personal_form_alter(&$form, &$form_state, $fo
 
   // Conditionally remove subject line.
   if (TRUE == variable_get('contact_plus_user_subj', FALSE)) {
-    // need to make the field not required here
+    // Need to make the field not required here.
     $form['subject']['#required'] = FALSE;
     $form['subject']['#access'] = FALSE;
   }
@@ -398,7 +406,6 @@ function contact_plus_form_contact_personal_form_alter(&$form, &$form_state, $fo
   $form['#submit'][] = 'contact_plus_submit_user_contact';
 }
 
-
 /**
  * Implements hook_form_FORM_ID_alter().
  */
@@ -417,7 +424,7 @@ function contact_plus_form_contact_category_edit_form_alter(&$form, &$form_state
     '#weight' => '-2',
   );
 
-  // if the token module exists then provide global token support
+  // If the token module exists then provide global token support.
   if (module_exists('token')) {
     $form['token_help'] = array(
       '#theme' => 'token_tree',
@@ -429,12 +436,11 @@ function contact_plus_form_contact_category_edit_form_alter(&$form, &$form_state
   $form['#submit'][] = 'contact_plus_submit_category';
 }
 
-
 /**
  * Custom submit handler for the 'submit sitewide contact form' page.
  */
 function contact_plus_submit_site_contact($form, &$form_state) {
-  // blank path (default value of '') indicates front page
+  // Blank path (default value of '') indicates front page.
   $path = variable_get('contact_plus_path_' . $form_state['values']['cid'], '');
 
   // If the path is an empty string, use the default redirect (front page).
@@ -443,16 +449,15 @@ function contact_plus_submit_site_contact($form, &$form_state) {
     return;
   }
 
-  // validate the path and set the required redirect
+  // Validate the path and set the required redirect.
   contact_plus_validate_path($path, $form_state);
 }
 
-
 /**
  * Custom submit handler for the 'submit user contact form' page.
  */
 function contact_plus_submit_user_contact($form, &$form_state) {
-  // blank path (default value of '') indicates front page
+  // Blank path (default value of '') indicates front page.
   $path = variable_get('contact_plus_user_path', '');
 
   // If the path is an empty string, use the default redirect.
@@ -462,41 +467,46 @@ function contact_plus_submit_user_contact($form, &$form_state) {
     return;
   }
 
-  // validate the path and set the required redirect
+  // Validate the path and set the required redirect.
   contact_plus_validate_path($path, $form_state);
 }
 
-
 /**
  * Validate paths and set redirect in form state for BOTH forms.
  */
 function contact_plus_validate_path($path, &$form_state) {
   global $user;
 
-  // if the token module exists then replace any tokens in the path
+  // If the token module exists then replace any tokens in the path.
   if (module_exists('token')) {
     $path = token_replace($path);
   }
 
   // Set the form to redirect to the path saved for users.
   if (drupal_valid_path($path, FALSE)) {
-    // path is valid, set the redirect
+    // Path is valid, set the redirect.
     $form_state['redirect'] = $path;
-  } else {
-    // set watchdog warning message
+  }
+  else {
+    // Set watchdog warning message.
     watchdog('Contact Plus',
       "Path was deemed invalid or user had insufficient permission. You may need to alter your path redirects.</br>
       Attempted to redirect user '%user' (uid %uid) to the path '%path' from form id '%form'.",
-      array('%user' => $user->name, '%uid' => $user->uid, '%path' => $path,
-            '%form' => $form_state['build_info']['form_id'], WATCHDOG_NOTICE));
+      array(
+        '%user' => $user->name,
+        '%uid' => $user->uid,
+        '%path' => $path,
+        '%form' => $form_state['build_info']['form_id'],
+      ),
+      WATCHDOG_NOTICE
+    );
 
-    // redirect to front page in case of failure
+    // Redirect to front page in case of failure.
     $form_state['redirect'] = '';
   }
-  // just drop out here, $form_state redirect is now set (passed by ref).
+  // Just drop out here, $form_state redirect is now set (passed by ref).
 }
 
-
 /**
  * Custom submit handler for the category settings form.
  */
@@ -507,7 +517,6 @@ function contact_plus_submit_category($form, &$form_state) {
   variable_set('contact_plus_path_' . $form_state['values']['cid'], $path);
 }
 
-
 /**
  * Custom submit handler for the user settings form.
  */
-- 
1.9.1

