Hi, I had success in adding my own plugin to add spanish provinces to the "administrative_area" field and making Spain the only country as a hidden value (http://drupal.org/node/968112#comment-5102646).

But If I want to add my own custom field (contact phone number) I have a lot of troubles...

This is the code in my PLUGIN_NAME.inc file:

$plugin = array(
  'title' => t('Address form (ES add-on)'),
  'format callback' => 'MODULE_NAME_spanish_address_generate',
  'type' => 'address',
  'weight' => -99,
);

/**
 * Format callback.
 *
 * @see CALLBACK_addressfield_format_callback()
 */
function MODULE_NAME_spanish_address_generate(&$format, $address, $context = array()) {
  if ($address['country'] == 'ES') {  
    // Add User Block with Contact Phone field.
    $format['user_block'] = array(
      '#type' => 'addressfield_container',
      '#attributes' => array('class' => array('user-block')),
      '#weight' => 200,
    );
    $format['user_block']['phone_contact_number'] = array(
      '#title' => t('Contact Phone'),
      '#type' => 'textfield', // If I remove this line it doesn't show at all
      '#tag' => 'div',
      '#attributes' => array('class' => array('contact-phone')),
      '#size' => 30,
      '#required' => TRUE,
    );
  }
}

When going to the CheckOut (first step) my field appears in both the Billing and Shipping Information. But if I fill them and continue to the next step (Checkout review) I can see the rest of the address fields rendered normally but my Phone field is shown as an editable form textfield (with no value inside). Then if I go back to the first step all fields except mine are correctly filled in.

Am I missing something? I have read the "address.inc" plugin and don't know what else to do.
Thanx in advance.

Comments

EndEd’s picture

Hi, I've just saw this issue http://drupal.org/node/1179804 Tried it and it works!

After all it was just as simple as that.

scoff’s picture

I need exactly that (phone number field) but not for a Commerce project/ Could someone point to a good address field plugin example?

davidwhthomas’s picture

I need this same functionality for additional fields within the address field, in this case special block/flat/tower fields for Hong Kong only.

I could add to the billing info profile type, but a preferable solution would be to add to the actual addressfield, so it will swap out correctly on country select.

I have a custom addressfield plugin and tried added the fields manually but got the same result as OP in #1

Is there another way to add additional fields to the addressfield block, perhaps using the 'data' column?

thanks,

DT

TimelessDomain’s picture

davidwhthomas’s picture

I was able to add custom fields to the data column using a custom addressfield plugin and hook_field_attach_load and hook_field_attach_presave more info here http://drupal.org/node/1225292#comment-5283840

jessehs’s picture

@davidwhthomas,

I saw your post at the link you mentioned. Can you provide more specifics about the render function you used to render the extra field(s)?

Thanks!

jessehs’s picture

For any developer wishing to further progress on this functionality, I created a sandbox project "addressfield_phone" as a jumping-off point here: http://drupal.org/sandbox/jessehs/1392068'

I've presently stopped development on the module, although I think it should be working minus the render function I mentioned in #6. I welcome any additional help here. If you want to get it working 100%, I'd be willing to co-maintain this add-on module as a full-fledged Drupal project (even though I no longer need it for my current projects). Contact me to get the ball rolling again!

Cheers!

jessehs’s picture

Status: Active » Closed (works as designed)

I think the solution is clear, and it's not part of this module, so I'm marking this as done (works as designed).

jcisio’s picture

Link in #7 updated as it became a full project:
http://drupal.org/project/addressfield_phone

jcisio’s picture

Issue summary: View changes

Changed code to php