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

Babalu’s picture

hmm for me its still not working

wickwood’s picture

This 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.

msypes’s picture

It 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) -

  1. Address Name
  2. First Name
  3. Last Name
  4. Business Name
  5. Street
  6. Additional
  7. City
  8. Province
  9. Postal Code
  10. Country
  11. Primary Address Checkbox
  12. Phone
  13. Fax
  14. Notes
  15. Alias
  16. Business Category (set to none)

A content type using this field has the apparent weighting of

  1. Address Name
  2. Street
  3. Additional
  4. City
  5. Province
  6. Postal Code
  7. Country
  8. Primary Address Checkbox
  9. First Name
  10. Alias
  11. Business Name
  12. Last Name
  13. Notes
  14. Phone
  15. Fax

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.

AlexisWilke’s picture

Title: Addresses field order don't work for adresses extras » Addresses field order don't work for addresses extras
Status: Active » Fixed

This is fixed.

Thank you.
Alexis Wilke

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.