You are here

function om_user_alter in OM Tools 7.2

Same name and namespace in other branches
  1. 8.2 tools/user/user.inc \om_user_alter()
  2. 8 tools/user/user.inc \om_user_alter()
  3. 6 tools/user/user.inc \om_user_alter()
  4. 7 tools/user/user.inc \om_user_alter()

OM Tools User Form Alters

File

tools/user/user.inc, line 80
OM Tools - User Tools for Drupal

Code

function om_user_alter(&$form, &$form_state, $form_id) {
  global $user;
  if ($user->uid != 0) {
    $form_id = '';
  }
  $user_defaults = $form['om_user_tools_values']['#value'];

  // Make sure the js are added only once
  static $user_login_block_js = 0;
  static $user_login_js = 0;
  static $user_register_js = 0;
  static $user_pass_js = 0;
  switch ($form_id) {
    case "user_login_block":
      if (isset($user_defaults['user_login_block_switch']) && $user_defaults['user_login_block_switch'] == 1) {
        $user_login_block_label = $user_defaults['user_login_block_label'];
        $user_login_block_name_label_text = $user_defaults['user_login_block_name_label_text'];
        $user_login_block_pass_label_text = $user_defaults['user_login_block_pass_label_text'];
        $user_login_block_size = $user_defaults['user_login_block_size'];
        $user_login_block_name_hover = $user_defaults['user_login_block_name_hover'];
        $user_login_block_pass_hover = $user_defaults['user_login_block_pass_hover'];
        $user_login_block_button = $user_defaults['user_login_block_button'];
        $user_login_block_register = $user_defaults['user_login_block_register'];
        $user_login_block_password = $user_defaults['user_login_block_password'];
        $user_login_block_links = '<div class="item-list"><ul><li class="first"><a href="' . base_path() . 'user/register" title="Create a new user account.">' . $user_login_block_register . '</a></li> <li class="last"><a href="' . base_path() . 'user/password" title="Request new password via e-mail.">' . $user_login_block_password . '</a></li> </ul></div>';
        if ($user_login_block_label) {
          unset($form['name']['#title']);
          unset($form['pass']['#title']);

          //$form['name']['#default_value'] = $user_login_block_name_label_text;
          $user_login_block_js++;
          if ($user_login_block_js == 1) {
            drupal_add_js(OM_TOOLS_PATH . '/tools/user/jquery.om_tools_user.js', 'file');
            drupal_add_js("    \n              jQuery(document).ready(function(\$){\n              \n                \$('#user-login-form').om_tools_user({\n                  'form_id'       : 'user_login_block',\n                  'user_defaults' : { user_login_block_label           : '" . $user_login_block_label . "', \n                                      user_login_block_name_label_text : '" . $user_login_block_name_label_text . "', \n                                      user_login_block_pass_label_text : '" . $user_login_block_pass_label_text . "', \n                                      user_login_block_size            : '" . $user_login_block_size . "', \n                                      user_login_block_pass_hover      : '" . $user_login_block_pass_hover . "'}\n                });\n              });           \n             ", "inline");
          }
        }
        else {
          $form['name']['#title'] = $user_login_block_name_label_text;
          $form['pass']['#title'] = $user_login_block_pass_label_text;
        }
        $form['name']['#size'] = $user_login_block_size;
        $form['name']['#attributes'] = array(
          'title' => t($user_login_block_name_hover),
        );
        $form['pass']['#size'] = $user_login_block_size;
        $form['pass']['#attributes'] = array(
          'title' => t($user_login_block_pass_hover),
        );
        $form['actions']['submit'] = array(
          '#type' => 'submit',
          '#value' => t($user_login_block_button),
        );
        $form['links']['#markup'] = $user_login_block_links;
      }
      break;
    case "user_login":
      if (isset($user_defaults['user_login_switch']) && $user_defaults['user_login_switch'] == 1) {
        drupal_set_title(t($user_defaults['user_login_title']));
        $user_login_label = $user_defaults['user_login_label'];
        $user_login_name_label_text = $user_defaults['user_login_name_label_text'];
        $user_login_name_description = $user_defaults['user_login_name_description'];
        $user_login_pass_label_text = $user_defaults['user_login_pass_label_text'];
        $user_login_pass_description = $user_defaults['user_login_pass_description'];
        $user_login_size = $user_defaults['user_login_size'];
        $user_login_name_hover = $user_defaults['user_login_name_hover'];
        $user_login_pass_hover = $user_defaults['user_login_pass_hover'];
        $user_login_button = $user_defaults['user_login_button'];
        if ($user_login_label) {
          unset($form['name']['#title']);
          unset($form['pass']['#title']);

          //$form['name']['#default_value'] = $user_login_name_label_text;
          $user_login_js++;
          if ($user_login_js == 1) {
            drupal_add_js(OM_TOOLS_PATH . '/tools/user/jquery.om_tools_user.js', 'file');
            drupal_add_js("\n               jQuery(document).ready(function(\$){\n                 \$('#user-login').om_tools_user({\n                   'form_id'       : 'user_login',\n                   'user_defaults' : { user_login_label           : '" . $user_login_label . "', \n                                       user_login_name_label_text : '" . $user_login_name_label_text . "', \n                                       user_login_pass_label_text : '" . $user_login_pass_label_text . "', \n                                       user_login_size            : '" . $user_login_size . "', \n                                       user_login_pass_hover      : '" . $user_login_pass_hover . "'}\n                });\n              });           \n             ", "inline");
          }
        }
        else {
          $form['name']['#title'] = $user_login_name_label_text;
          $form['pass']['#title'] = $user_login_pass_label_text;
        }
        $form['name']['#description'] = $user_login_name_description;
        $form['name']['#size'] = $user_login_size;
        $form['name']['#attributes'] = array(
          'title' => t($user_login_name_hover),
        );
        $form['pass']['#description'] = $user_login_pass_description;
        $form['pass']['#size'] = $user_login_size;
        $form['pass']['#attributes'] = array(
          'title' => t($user_login_pass_hover),
        );
        $form['actions']['submit'] = array(
          '#type' => 'submit',
          '#value' => t($user_login_button),
        );
      }
      break;
    case "user_register_form":
      if (isset($user_defaults['user_register_switch']) && $user_defaults['user_register_switch'] == 1) {
        drupal_set_title(t($user_defaults['user_register_title']));
        $user_register_label = $user_defaults['user_register_label'];
        $user_register_name_label_text = $user_defaults['user_register_name_label_text'];
        $user_register_name_description = $user_defaults['user_register_name_description'];
        $user_register_mail_label_text = $user_defaults['user_register_mail_label_text'];
        $user_register_mail_description = $user_defaults['user_register_mail_description'];
        $user_register_size = $user_defaults['user_register_size'];
        $user_register_name_hover = $user_defaults['user_register_name_hover'];
        $user_register_mail_hover = $user_defaults['user_register_mail_hover'];
        $user_register_button = $user_defaults['user_register_button'];
        if ($user_register_label) {
          unset($form['account']['name']['#title']);
          unset($form['account']['mail']['#title']);

          //$form['account']['name']['#default_value'] = $user_register_name_label_text;
          $user_register_js++;
          if ($user_register_js == 1) {
            drupal_add_js(OM_TOOLS_PATH . '/tools/user/jquery.om_tools_user.js', 'file');
            drupal_add_js("\n              jQuery(document).ready(function(\$){\n                 \$('#user-register-form').om_tools_user({\n                   'form_id'       : 'user_register_form',\n                   'user_defaults' : { user_register_name_label_text : '" . $user_register_name_label_text . "', \n                                       user_register_mail_label_text : '" . $user_register_mail_label_text . "'}\n                });\n              });           \n            ", "inline");
          }
        }
        else {
          $form['account']['name']['#title'] = $user_register_name_label_text;
          $form['account']['mail']['#title'] = $user_register_mail_label_text;
        }
        $form['account']['name']['#description'] = $user_register_name_description;
        $form['account']['name']['#size'] = $user_register_size;
        $form['account']['name']['#attributes'] = array(
          'title' => t($user_register_name_hover),
        );
        $form['account']['mail']['#description'] = $user_register_mail_description;
        $form['account']['mail']['#size'] = $user_register_size;
        $form['account']['mail']['#attributes'] = array(
          'title' => t($user_register_mail_hover),
        );
        $form['actions']['submit'] = array(
          '#type' => 'submit',
          '#value' => t($user_register_button),
        );
      }
      break;
    case "user_pass":
      if (isset($user_defaults['user_pass_switch']) && $user_defaults['user_pass_switch'] == 1) {
        drupal_set_title(t($user_defaults['user_pass_title']));
        $user_pass_label = $user_defaults['user_pass_label'];
        $user_pass_name_label_text = $user_defaults['user_pass_name_label_text'];
        $user_pass_name_description = $user_defaults['user_pass_name_description'];
        $user_pass_size = $user_defaults['user_pass_size'];
        $user_pass_name_hover = $user_defaults['user_pass_name_hover'];
        $user_pass_button = $user_defaults['user_pass_button'];
        if ($user_pass_label) {
          unset($form['name']['#title']);
          unset($form['mail']['#title']);

          //$form['name']['#default_value'] = $user_pass_name_label_text;
          $user_pass_js++;
          if ($user_pass_js == 1) {
            drupal_add_js(OM_TOOLS_PATH . '/tools/user/jquery.om_tools_user.js', 'file');
            drupal_add_js("\n              jQuery(document).ready(function(\$){\n                 \$('#user-pass').om_tools_user({\n                   'form_id'       : 'user_pass',\n                   'user_defaults' : { user_pass_name_label_text : '" . $user_pass_name_label_text . "'}\n                });\n              });           \n            ", "inline");
          }
        }
        else {
          $form['name']['#title'] = $user_pass_name_label_text;
        }
        $form['name']['#description'] = $user_pass_name_description;
        $form['name']['#size'] = $user_pass_size;
        $form['name']['#attributes'] = array(
          'title' => t($user_pass_name_hover),
        );
        $form['actions']['submit'] = array(
          '#type' => 'submit',
          '#value' => t($user_pass_button),
        );
      }
      break;
  }
}