When i change field order in addresses settings pages, extras field (last name, first name ...) are in weight position 0 on edit account page !
In fact, #weight isn't specified in function addresses_names_addressesfieldapi with $op == 'form' (file addresses_names.module)
If i use addresses module method, all it's ok :
Line 75 I ad :
$field_weights = variable_get('addresses_field_weight', array());
And for each form element i had #weight information (first name for exemple) :
'#weight' => empty($field_weights['first_name']['weight']) ? 0 :
$field_weights['first_name']['weight'],
ps: Sorry for my very bad english ...
Complete addresses_names_addressesfieldapi function changed
/**
* Implementation of hook_addressfieldapi().
*
* Its a specific Addresses module hook function, to
* allow other modules to add more fields to the addresses
*/
function addresses_names_addressesfieldapi($op, $fields = array(), $values = array()) {
if ($op == 'fields') {
return array(
'first_name' => array(
'type' => 'varchar',
'length' => 75,
'description' => t('Your first name.'),
'display' => ADDRESSES_FIELD_SHOW,
'title' => t('First Name'),
'theme' => array(
'first_name' => t('First Name.'),
),
'token' => 'addresses_general',
),
'last_name' => array(
'type' => 'varchar',
'length' => 75,
'description' => t('Your last name.'),
'display' => ADDRESSES_FIELD_SHOW,
'title' => t('Last Name'),
'theme' => array(
'last_name' => t('Last Name.'),
),
'token' => 'addresses_general',
),
'alias' => array(
'type' => 'varchar',
'length' => 75,
'description' => t('Alias'),
'display' => ADDRESSES_FIELD_NONE,
'title' => t('Alias'),
'theme' => array(
'alias' => t('Alias.'),
),
'token' => 'addresses_general',
),
'business' => array(
'type' => 'varchar',
'length' => 75,
'description' => t('Business Name (dba)'),
'display' => ADDRESSES_FIELD_SHOW,
'title' => t('Business Name'),
'theme' => array(
'business' => t('Business Name.'),
),
'token' => 'addresses_adr',
),
'bizcategory' => array(
'type' => 'varchar',
'length' => 75,
'description' => t('Business Category'),
'display' => ADDRESSES_FIELD_SHOW,
'title' => t('Business Category'),
'theme' => array(
'bizcategory' => t('Business Category.'),
),
'token' => 'addresses_adr',
),
);
}
elseif ($op == 'form') {
$field_weights = variable_get('addresses_field_weight', array());
// First name
if ($fields['first_name'] == ADDRESSES_FIELD_HIDDEN) {
$form['first_name'] = array(
'#type' => 'hidden',
'#value' => isset($values['first_name']) ? $values['first_name'] : '',
);
}
elseif (!empty($fields['first_name'])) {
$form['first_name'] = array(
'#type' => 'textfield',
'#title' => t('First Name'),
'#description' => t('Name of your business point of contact.'),
'#default_value' => isset($values['first_name']) ? $values['first_name'] : '',
'#size' => 50,
'#maxlength' => 75,
'#attributes' => NULL,
'#required' => ($fields['first_name'] == ADDRESSES_FIELD_REQUIRED),
'#weight' => empty($field_weights['first_name']['weight']) ? 0 :
$field_weights['first_name']['weight'],
);
}
// Last name
if ($fields['last_name'] == ADDRESSES_FIELD_HIDDEN) {
$form['last_name'] = array(
'#type' => 'hidden',
'#value' => isset($values['last_name']) ? $values['last_name'] : '',
);
}
elseif (!empty($fields['last_name'])) {
$form['last_name'] = array(
'#type' => 'textfield',
'#title' => t('Last Name'),
'#description' => t('Name of your business point of contact.'),
'#default_value' => isset($values['last_name']) ? $values['last_name'] : '',
'#size' => 50,
'#maxlength' => 75,
'#attributes' => NULL,
'#required' => ($fields['last_name'] == ADDRESSES_FIELD_REQUIRED),
'#weight' => empty($field_weights['last_name']['weight']) ? 0 :
$field_weights['last_name']['weight'],
);
}
// Alias name
if ($fields['alias'] == ADDRESSES_FIELD_HIDDEN) {
$form['alias'] = array(
'#type' => 'hidden',
'#value' => isset($values['alias']) ? $values['alias'] : '',
);
}
elseif (!empty($fields['alias'])) {
$form['alias'] = array(
'#type' => 'textfield',
'#title' => t('Alias'),
'#default_value' => isset($values['alias']) ? $values['alias'] : '',
'#size' => 50,
'#maxlength' => 75,
'#attributes' => NULL,
'#required' => ($fields['alias'] == ADDRESSES_FIELD_REQUIRED),
'#weight' => empty($field_weights['alias']['weight']) ? 0 :
$field_weights['alias']['weight'],
);
}
// Business name
if ($fields['business'] == ADDRESSES_FIELD_HIDDEN) {
$form['business'] = array(
'#type' => 'hidden',
'#value' => isset($values['business']) ? $values['business'] : '',
);
}
elseif (!empty($fields['business'])) {
$form['business'] = array(
'#type' => 'textfield',
'#title' => t('Business'),
'#default_value' => isset($values['business']) ? $values['business'] : '',
'#size' => 50,
'#maxlength' => 75,
'#attributes' => NULL,
'#required' => ($fields['business'] == ADDRESSES_FIELD_REQUIRED),
'#weight' => empty($field_weights['business']['weight']) ? 0 :
$field_weights['business']['weight'],
);
}
// Category
if ($fields['bizcategory'] == ADDRESSES_FIELD_HIDDEN) {
$form['bizcategory'] = array(
'#type' => 'hidden',
'#value' => isset($values['bizcategory']) ? $values['bizcategory'] : '',
);
}
elseif (!empty($fields['bizcategory'])) {
$form['bizcategory'] = array(
'#type' => 'textfield',
'#title' => t('Category'),
'#default_value' => isset($values['bizcategory']) ? $values['bizcategory'] : '',
'#size' => 50,
'#maxlength' => 75,
'#attributes' => NULL,
'#required' => ($fields['bizcategory'] == ADDRESSES_FIELD_REQUIRED),
'#weight' => empty($field_weights['bizcategory']['weight']) ? 0 :
$field_weights['bizcategory']['weight'],
);
}
return $form;
}
}
Comments
Comment #1
Babalu commentedhmm for me its still not working
Comment #2
wickwood commentedThis is not working for me either, and I just discovered this post. I don't quite understand if this post is offering a fix or just pointing out the problem.
Brand new install of Drupal 6.12, Addresses and Address Extras.
Comment #3
msypes commentedIt looked like a fix to me, so I tried adding in the #weight lines as appropriate. I don't see that it's having the proper effect either:
Weight Settings in Addresses
(Note that the Drag&Drop visual placement of the items doesn't match, but that seems to be a separate issue [http://drupal.org/node/413088] also noted by zedzed) -
A content type using this field has the apparent weighting of
Is possible that CCK, Addresses, and Address_Extras are coming up with their own internal weights and not communicating them to one another for consistency?
I'm also very new to Drupal, and not sure how the modules "play" together.
Comment #4
AlexisWilke commentedThis is fixed.
Thank you.
Alexis Wilke