Commit 3eec2bc8 authored by Steve Gerbino's avatar Steve Gerbino

Issue #1220206 by mibfire: Corrected an issue where core profile

fields in category did not receive a weight modification by the
module.
parent 10d0767e
......@@ -14,7 +14,6 @@
function realname_registration_settings_form() {
$form = array();
// If the content_profile module doesn't exist we must make sure these values are reset.
if (!module_exists('content_profile_registration')) {
variable_set('realname_registration_use_content_profile_firstname_field', 0);
variable_set('realname_registration_content_profile_firstname_field_node', 0);
......@@ -23,7 +22,7 @@ function realname_registration_settings_form() {
variable_set('realname_registration_use_content_profile_lastname_field', 0);
variable_set('realname_registration_content_profile_lastname_field_node', 0);
}
$field_req = '<ul><li>'
. t('The field name is correct and represents an existing profile field') . '</li><li>'
. t('The field is required and displays on the registration form') . '</li></ul>';
......@@ -36,6 +35,11 @@ function realname_registration_settings_form() {
'#description' => t('The name of your first name field. Ensure that:') . $field_req,
);
$form['realname_registration_firstname_field_category'] = array(
'#type' => 'value',
'#value' => variable_get('realname_registration_firstname_field_category', ''),
);
if (module_exists('content_profile_registration')) {
$form['realname_registration_use_content_profile_firstname_field'] = array(
'#type' => 'checkbox',
......@@ -58,6 +62,11 @@ function realname_registration_settings_form() {
. t('The field is displayed on the registration form') . '</li></ul>',
);
$form['realname_registration_middlename_field_category'] = array(
'#type' => 'value',
'#value' => variable_get('realname_registration_middlename_field_category', ''),
);
if (module_exists('content_profile_registration')) {
$form['realname_registration_use_content_profile_middlename_field'] = array(
'#type' => 'checkbox',
......@@ -79,6 +88,11 @@ function realname_registration_settings_form() {
'#description' => t('The name of your last name field. Ensure that:') . $field_req,
);
$form['realname_registration_lastname_field_category'] = array(
'#type' => 'value',
'#value' => variable_get('realname_registration_lastname_field_category', ''),
);
if (module_exists('content_profile_registration')) {
$form['realname_registration_use_content_profile_lastname_field'] = array(
'#type' => 'checkbox',
......@@ -141,7 +155,7 @@ function realname_registration_settings_validate($form, &$form_state) {
// Validation for the first name field.
if ($form_state['values']['realname_registration_use_content_profile_firstname_field'] == 0 ) {
$firstname_field = db_fetch_object(db_query("SELECT type, required, register FROM {profile_fields} WHERE name = '%s'", $form_state['values']['realname_registration_firstname_field']));
$firstname_field = db_fetch_object(db_query("SELECT type, required, register, category FROM {profile_fields} WHERE name = '%s'", $form_state['values']['realname_registration_firstname_field']));
if (empty($firstname_field)) {
form_set_error('realname_registration_firstname_field', $err_pretext . $form_state['values']['realname_registration_firstname_field'] . $err_unknown);
}
......@@ -154,6 +168,9 @@ function realname_registration_settings_validate($form, &$form_state) {
if ($firstname_field->register != 1) {
form_set_error('realname_registration_firstname_field', $err_pretext . $form_state['values']['realname_registration_firstname_field'] . $err_register);
}
if ($firstname_field->category) {
$form_state['values']['realname_registration_firstname_field_category'] = $firstname_field->category;
}
}
else {
$sql = "SELECT i.field_name, i.type_name, i.widget_type, c.required "
......@@ -187,7 +204,7 @@ function realname_registration_settings_validate($form, &$form_state) {
// Validation for the middle name field.
if (!empty($form_state['values']['realname_registration_middlename_field'])) {
if ($form_state['values']['realname_registration_use_content_profile_middlename_field'] == 0) {
$middlename_field = db_fetch_object(db_query("SELECT type, required, register FROM {profile_fields} WHERE name = '%s'", $form_state['values']['realname_registration_middlename_field']));
$middlename_field = db_fetch_object(db_query("SELECT type, required, register, category FROM {profile_fields} WHERE name = '%s'", $form_state['values']['realname_registration_middlename_field']));
if (empty($middlename_field)) {
form_set_error('realname_registration_middlename_field', $err_pretext . $form_state['values']['realname_registration_middlename_field'] . $err_unknown);
}
......@@ -197,6 +214,9 @@ function realname_registration_settings_validate($form, &$form_state) {
if ($middlename_field->register != 1) {
form_set_error('realname_registration_middlename_field', $err_pretext . $form_state['values']['realname_registration_middlename_field'] . $err_register);
}
if ($middlename_field->category) {
$form_state['values']['realname_registration_middlename_field_category'] = $middlename_field->category;
}
}
else {
$sql = "SELECT i.field_name, i.type_name, i.widget_type, c.required "
......@@ -227,7 +247,7 @@ function realname_registration_settings_validate($form, &$form_state) {
// Validation for the last name field.
if ($form_state['values']['realname_registration_use_content_profile_lastname_field'] == 0) {
$lastname_field = db_fetch_object(db_query("SELECT type, required, register FROM {profile_fields} WHERE name = '%s'", $form_state['values']['realname_registration_lastname_field']));
$lastname_field = db_fetch_object(db_query("SELECT type, required, register, category FROM {profile_fields} WHERE name = '%s'", $form_state['values']['realname_registration_lastname_field']));
if (empty($lastname_field)) {
form_set_error('realname_registration_lastname_field', $err_pretext . $form_state['values']['realname_registration_lastname_field'] . $err_unknown);
}
......@@ -240,6 +260,9 @@ function realname_registration_settings_validate($form, &$form_state) {
if ($lastname_field->register != 1) {
form_set_error('realname_registration_lastname_field', $err_pretext . $form_state['values']['realname_registration_lastname_field'] . $err_register);
}
if ($lastname_field->category) {
$form_state['values']['realname_registration_lastname_field_category'] = $lastname_field->category;
}
}
else {
$sql = "SELECT i.field_name, i.type_name, i.widget_type, c.required "
......
......@@ -32,4 +32,4 @@ function realname_registration_requirements($phase) {
*/
function realname_registration_install() {
db_query("UPDATE {system} SET weight = 10 WHERE name = 'realname_registration'");
}
}
\ No newline at end of file
......@@ -7,6 +7,7 @@
* required first name and last name CCK fields on the registration form.
*/
/*
* Implementation of hook_enable().
*/
......@@ -35,7 +36,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(!empty($lastname_field) && !empty($firstname_field)) {
if (!empty($lastname_field) && !empty($firstname_field)) {
// First, we must hide the Username field from the registration form.
if (isset($form['account']) && is_array($form['account'])) {
$form['account']['name']['#type'] = 'hidden';
......@@ -48,15 +49,25 @@ function realname_registration_form_alter(&$form, $form_state, $form_id) {
// We must bring the name fields up so that they show at the top of the form.
if (!variable_get('realname_registration_use_content_profile_firstname_field', 0)) {
$form[$firstname_field]['#weight'] = -500;
if (variable_get('realname_registration_firstname_field_category', '')) {
$form[variable_get('realname_registration_firstname_field_category', '')][$firstname_field]['#weight'] = -500;
}
else {
$form[$firstname_field]['#weight'] = -500;
}
}
else {
$form['#field_info'][$firstname_field]['widget']['weight'] = -500;
}
if (!variable_get('realname_registration_use_content_profile_middlename_field', 0)) {
if(!empty($middlename_field)) {
$form[$middlename_field]['#weight'] = -499;
if (!empty($middlename_field)) {
if (variable_get('realname_registration_middlename_field_category', '')) {
$form[variable_get('realname_registration_middlename_field_category', '')][$middlename_field]['#weight'] = -499;
}
else {
$form[$middlename_field]['#weight'] = -499;
}
}
}
else {
......@@ -66,7 +77,12 @@ function realname_registration_form_alter(&$form, $form_state, $form_id) {
}
if (!variable_get('realname_registration_use_content_profile_lastname_field', 0)) {
$form[$lastname_field]['#weight'] = -498;
if (variable_get('realname_registration_lastname_field_category', '')) {
$form[variable_get('realname_registration_lastname_field_category', '')][$lastname_field]['#weight'] = -498;
}
else {
$form[$lastname_field]['#weight'] = -498;
}
}
else {
$form['#field_info'][$lastname_field]['widget']['weight'] = -498;
......
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