Commit 0ad584cb authored by Steve Gerbino's avatar Steve Gerbino

Clean up code so that it better adheres to Drupal coding standards.

parent 7e0e659b
......@@ -14,19 +14,19 @@
function realname_registration_settings_form() {
$form = array();
$field_req = "
$field_req = '
<ul>
<li>".t('The field name is correct and represents an existing field')."</li>
<li>".t('The field is associated with the').' <em>'.t('user')."</em> ".t('entity')."</li>
<li>".t('The field is required and displays on the registration form')."</li>
<li>' . t('The field name is correct and represents an existing field') . '</li>
<li>' . t('The field is associated with the') . ' <em>' . t('user') . '</em> ' . t('entity') . '</li>
<li>' . t('The field is required and displays on the registration form') . '</li>
</ul>
";
';
$form['realname_registration_firstname_field'] = array(
'#type' => 'textfield',
'#title' => t('First name field'),
'#default_value' => variable_get('realname_registration_firstname_field'),
'#description' => t("The name of your first name field. Ensure that:").$field_req,
'#description' => t('The name of your first name field. Ensure that:') . $field_req,
'#required' => TRUE,
);
......@@ -35,7 +35,7 @@ function realname_registration_settings_form() {
'#title' => t('Middle name field'),
'#default_value' => variable_get('realname_registration_middlename_field'),
'#description' =>
t("The name of your middle name field. Ensure that:")
t('The name of your middle name field. Ensure that:')
. '<ul>'
. '<li>' . t('The field name is correct and represents an existing field') . '</li>'
. '<li>' . t('The field is associated with the') . ' <em>' . t('user') . '</em> ' . t('entity') . '</li>'
......@@ -46,7 +46,7 @@ function realname_registration_settings_form() {
'#type' => 'textfield',
'#title' => t('Last name field'),
'#default_value' => variable_get('realname_registration_lastname_field'),
'#description' => t("The name of your last name field. Ensure that:").$field_req,
'#description' => t('The name of your last name field. Ensure that:') . $field_req,
'#required' => TRUE,
);
......@@ -68,21 +68,21 @@ function realname_registration_settings_form() {
'#type' => 'checkbox',
'#title' => t('Force the first letters of the first and last names to uppercase'),
'#default_value' => variable_get('realname_registration_ucfirst', 1),
'#description' => t("Ensures that the first letter of the users first name and first letter of the users last name are capitalized."),
'#description' => t('Ensures that the first letter of the users first name and first letter of the users last name are capitalized.'),
);
$form['realname_registration_tolower'] = array(
'#type' => 'checkbox',
'#title' => t('Force lowercase'),
'#default_value' => variable_get('realname_registration_tolower'),
'#description' => t("Usernames will be created using only lowercase characters."),
'#description' => t('Usernames will be created using only lowercase characters.'),
);
$form['realname_registration_use_validation'] = array(
'#type' => 'checkbox',
'#title' => t('Use Realname registration validation'),
'#default_value' => variable_get('realname_registration_use_validation', 1),
'#description' => t("Use regex to validate real names (/^[A-ZÀ-ÖØ-öø-ÿ]+$/i)"),
'#description' => t('Use regex to validate real names (/^[A-ZÀ-ÖØ-öø-ÿ]+$/i)'),
);
$form['#validate'][] = 'realname_registration_settings_validate';
......@@ -90,49 +90,49 @@ function realname_registration_settings_form() {
}
function realname_registration_settings_validate($form, &$form_state) {
$err_pretext = t('The field name').', <em>';
$err_req = '</em>, '.t("you've provided must be required.");
$err_unknown = '</em>, '.t("you've provided either does not exist or is not associated with the user entity and bundle.");
$err_textfield = '</em>, '.t('must use textfield widget.');
$err_pretext = t('The field name') . ', <em>';
$err_req = '</em>, ' . t("you've provided must be required.");
$err_unknown = '</em>, ' . t("you've provided either does not exist or is not associated with the user entity and bundle.");
$err_textfield = '</em>, ' . t('must use textfield widget.');
// Validate the first name field.
$firstname_instance = field_info_instance('user', $form_state['values']['realname_registration_firstname_field'], 'user');
if(!isset($firstname_instance)) {
form_set_error('realname_registration_firstname_field', $err_pretext.$form_state['values']['realname_registration_firstname_field'].$err_unknown);
if (!isset($firstname_instance)) {
form_set_error('realname_registration_firstname_field', $err_pretext . $form_state['values']['realname_registration_firstname_field'] . $err_unknown);
}
if($firstname_instance['widget']['type'] != 'text_textfield') {
form_set_error('realname_registration_firstname_field', $err_pretext.$form_state['values']['realname_registration_firstname_field'].$err_textfield);
if ($firstname_instance['widget']['type'] != 'text_textfield') {
form_set_error('realname_registration_firstname_field', $err_pretext . $form_state['values']['realname_registration_firstname_field'] . $err_textfield);
}
if($firstname_instance['required'] != 1) {
form_set_error('realname_registration_firstname_field', $err_pretext.$form_state['values']['realname_registration_firstname_field'].$err_req);
if ($firstname_instance['required'] != 1) {
form_set_error('realname_registration_firstname_field', $err_pretext . $form_state['values']['realname_registration_firstname_field'] . $err_req);
}
// Validate the middle name field if it is used.
if(!empty($form_state['values']['realname_registration_middlename_field'])) {
if (!empty($form_state['values']['realname_registration_middlename_field'])) {
$middlename_instance = field_info_instance('user', $form_state['values']['realname_registration_middlename_field'], 'user');
if(!isset($middlename_instance)) {
form_set_error('realname_registration_middlename_field', $err_pretext.$form_state['values']['realname_registration_middlename_field'].$err_unknown);
if (!isset($middlename_instance)) {
form_set_error('realname_registration_middlename_field', $err_pretext . $form_state['values']['realname_registration_middlename_field'] . $err_unknown);
}
if($middlename_instance['widget']['type'] != 'text_textfield') {
form_set_error('realname_registration_middlename_field', $err_pretext.$form_state['values']['realname_registration_middlename_field'].$err_textfield);
if ($middlename_instance['widget']['type'] != 'text_textfield') {
form_set_error('realname_registration_middlename_field', $err_pretext . $form_state['values']['realname_registration_middlename_field'] . $err_textfield);
}
}
else {
// If there is no middle name field provided, we can't base usernames off the middle initial.
if($form_state['values']['realname_registration_format'] == 2 || $form_state['values']['realname_registration_format'] == 3) {
if ($form_state['values']['realname_registration_format'] == 2 || $form_state['values']['realname_registration_format'] == 3) {
form_set_error('realname_registration_format', t('A valid middle name field is required for this username format.'));
}
}
// Validate the last name field.
$lastname_instance = field_info_instance('user', $form_state['values']['realname_registration_lastname_field'], 'user');
if(!isset($lastname_instance)) {
form_set_error('realname_registration_lastname_field', $err_pretext.$form_state['values']['realname_registration_lastname_field'].$err_unknown);
if (!isset($lastname_instance)) {
form_set_error('realname_registration_lastname_field', $err_pretext . $form_state['values']['realname_registration_lastname_field'] . $err_unknown);
}
if($lastname_instance['widget']['type'] != 'text_textfield') {
form_set_error('realname_registration_lastname_field', $err_pretext.$form_state['values']['realname_registration_lastname_field'].$err_textfield);
if ($lastname_instance['widget']['type'] != 'text_textfield') {
form_set_error('realname_registration_lastname_field', $err_pretext . $form_state['values']['realname_registration_lastname_field'] . $err_textfield);
}
if($lastname_instance['required'] != 1) {
form_set_error('realname_registration_lastname_field', $err_pretext.$form_state['values']['realname_registration_lastname_field'].$err_req);
if ($lastname_instance['required'] != 1) {
form_set_error('realname_registration_lastname_field', $err_pretext . $form_state['values']['realname_registration_lastname_field'] . $err_req);
}
}
\ No newline at end of file
......@@ -19,17 +19,17 @@ function realname_registration_help($path, $arg) {
$output .= '<h4>' . t('Settings') . '</h4>';
$output .= '<dl>';
$output .= '<dt><strong>' . t('Create your first name and last name fields') . '</strong></dt>';
$output .= '<dd>' .t('(If you already have these fields, take note of the names and skip this step)'). '</dd>';
$output .= '<dd>' .t('Navigate to <a href="../config/people/accounts/fields">admin/config/people/accounts/fields</a> and create a text field that will hold the user\'s first name.').' ';
$output .= t('While editing the field, ensure that the Required field option is checked, also to Display on the registration form.').' ';
$output .= '<dd>' . t('(If you already have these fields, take note of the names and skip this step)') . '</dd>';
$output .= '<dd>' . t('Navigate to <a href="../config/people/accounts/fields">admin/config/people/accounts/fields</a> and create a text field that will hold the user\'s first name.') . ' ';
$output .= t('While editing the field, ensure that the Required field option is checked, also to Display on the registration form.') . ' ';
$output .= t('Repeat this step for the last name field. Be sure to take note of what you have named the new fields.') . '</dd>';
$output .= '<dd><a href="../config/people/accounts/fields">'.t('Jump to Managing user fields').'</a></dd>';
$output .= '<dd><a href="../config/people/accounts/fields">' . t('Jump to Managing user fields') . '</a></dd>';
$output .= '</dl>';
$output .= '<dl>';
$output .= '<dt><strong>' . t('Configure the Realname registration module') . '</strong></dt>';
$output .= '<dd>' . t('Now that you have first name and last name fields associated with your users, you can map these fields in Realname registration.').' ';
$output .= t('Type the field names that you have created in the appropriate textfields, and select your other options and click Submit.'). '</dd>';
$output .= '<dd><a href="../config/people/realname_registration">'.t('Jump to Realname registration configuration').'</a></dd>';
$output .= '<dd>' . t('Now that you have first name and last name fields associated with your users, you can map these fields in Realname registration.') . ' ';
$output .= t('Type the field names that you have created in the appropriate textfields, and select your other options and click Submit.') . '</dd>';
$output .= '<dd><a href="../config/people/realname_registration">' . t('Jump to Realname registration configuration') . '</a></dd>';
$output .= '</dl>';
return $output;
}
......@@ -47,7 +47,7 @@ function realname_registration_form_alter(&$form, $form_state, $form_id) {
$middlename_field = variable_get('realname_registration_middlename_field');
$firstname_field = variable_get('realname_registration_firstname_field');
if(isset($lastname_field) && isset($firstname_field)) {
if (isset($lastname_field) && isset($firstname_field)) {
if (isset($form['account']) && is_array($form['account'])) {
$form['account']['name']['#type'] = 'hidden';
$form['account']['name']['#value'] = 'unset_username';
......@@ -59,13 +59,13 @@ function realname_registration_form_alter(&$form, $form_state, $form_id) {
$form[$firstname_field]['#weight'] = -500;
if(!empty($middlename_field)) {
if (!empty($middlename_field)) {
$form[$middlename_field]['#weight'] = -499;
}
$form[$lastname_field]['#weight'] = -498;
if(variable_get('realname_registration_use_validation')) {
if (variable_get('realname_registration_use_validation')) {
$form['#validate'][] = 'realname_registration_validate';
}
}
......@@ -75,46 +75,46 @@ function realname_registration_form_alter(&$form, $form_state, $form_id) {
* Implementation of hook_user_presave().
*/
function realname_registration_user_presave(&$edit, $account, $category) {
if(isset($edit['name'])) {
if (isset($edit['name'])) {
if ($edit['name'] == 'unset_username') {
$firstname_field = variable_get('realname_registration_firstname_field');
$middlename_field = variable_get('realname_registration_middlename_field');
$lastname_field = variable_get('realname_registration_lastname_field');
if((variable_get('realname_registration_ucfirst')) == 1) {
if ((variable_get('realname_registration_ucfirst')) == 1) {
$edit[$firstname_field]['und'][0]['value'] = ucfirst($edit[$firstname_field]['und'][0]['value']);
if(!empty($edit[$middlename_field]['und'][0]['value'])) {
if (!empty($edit[$middlename_field]['und'][0]['value'])) {
$edit[$middlename_field]['und'][0]['value'] = ucfirst($edit[$middlename_field]['und'][0]['value']);
}
$edit[$lastname_field]['und']['0']['value'] = ucfirst($edit[$lastname_field]['und'][0]['value']);
}
// Generate the username based on first name and last name fields.
if((variable_get('realname_registration_format')) == 0) {
if ((variable_get('realname_registration_format')) == 0) {
$username = $edit[$firstname_field]['und'][0]['value'] . " " . $edit[$lastname_field]['und'][0]['value'];
}
if((variable_get('realname_registration_format')) == 1) {
if ((variable_get('realname_registration_format')) == 1) {
$first_init = drupal_substr($edit[$firstname_field]['und'][0]['value'], 0, 1);
$lastname = $edit[$lastname_field]['und'][0]['value'];
$username = $first_init . $lastname;
}
if((variable_get('realname_registration_format')) == 2) {
if(!empty($edit[$middlename_field]['und'][0]['value'])) {
if ((variable_get('realname_registration_format')) == 2) {
if (!empty($edit[$middlename_field]['und'][0]['value'])) {
$username = $edit[$firstname_field]['und'][0]['value'] . " " . $edit[$middlename_field]['und'][0]['value'] . " " . $edit[$lastname_field]['und'][0]['value'];
}
else {
$username = $edit[$firstname_field]['und'][0]['value'] . " " . $edit[$lastname_field]['und'][0]['value'];
}
}
if((variable_get('realname_registration_format')) == 3) {
if ((variable_get('realname_registration_format')) == 3) {
$first_init = drupal_substr($edit[$firstname_field]['und'][0]['value'], 0, 1);
if(!empty($edit[$middlename_field]['und'][0]['value'])) {
if (!empty($edit[$middlename_field]['und'][0]['value'])) {
$middle_init = drupal_substr($edit[$middlename_field]['und'][0]['value'], 0, 1);
}
$lastname = $edit[$lastname_field]['und'][0]['value'];
$username = $first_init . $middle_init . $lastname;
}
if(variable_get('realname_registration_tolower')) {
if (variable_get('realname_registration_tolower')) {
$username = strtolower($username);
}
......@@ -125,7 +125,7 @@ function realname_registration_user_presave(&$edit, $account, $category) {
$i = 0;
while ($result->rowCount()) {
$result = db_query("SELECT name FROM {users} WHERE name = :username", array(':username' => $username . ++$i));
if(!($result->rowCount())) {
if (!($result->rowCount())) {
$username = $username . $i;
}
}
......@@ -169,8 +169,8 @@ function realname_registration_menu() {
$items = array();
$items['admin/config/people/realname_registration'] = array(
'title' => t('Realname registration'),
'description' => t('Administer settings for Realname registration.'),
'title' => 'Realname registration',
'description' => 'Administer settings for Realname registration.',
'page callback' => 'drupal_get_form',
'page arguments' => array('realname_registration_settings_form'),
'access arguments' => array('access administration pages'),
......
......@@ -47,7 +47,7 @@ function realname_registration_tokens($type, $tokens, array $data = array(), arr
$field_middlename = variable_get('realname_registration_middlename_field');
$field_lastname = variable_get('realname_registration_lastname_field');
if(isset($field_firstname) && isset($field_lastname)) {
if (isset($field_firstname) && isset($field_lastname)) {
if ($type == 'user' && !empty($data['user'])) {
$account = $data['user'];
foreach ($tokens as $name => $original) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment