addressfield.inc 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * Primary value passed to this field must be the two letter ISO country code of
  4. * the address.
  5. *
  6. * Arguments are used to specify all the other values:
  7. * 'administrative_area' - The administrative area of this address. (i.e. State/Province)
  8. * 'sub_administrative_area' - The sub administrative area of this address.
  9. * 'locality' - The locality of this address. (i.e. City)
  10. * 'dependent_locality' - The dependent locality of this address.
  11. * 'postal_code' - The postal code of this address.
  12. * 'thoroughfare' - The thoroughfare of this address. (i.e. Street address)
  13. * 'premise' - The premise of this address. (i.e. Apartment / Suite number)
  14. * 'sub_premise' - The sub_premise of this address.
  15. * 'organisation_name' - Contents of a primary OrganisationName element in the xNL XML.
  16. * 'name_line' - Contents of a primary NameLine element in the xNL XML.
  17. * 'first_name' - Contents of the FirstName element of a primary PersonName element in the xNL XML.
  18. * 'last_name' - Contents of the LastName element of a primary PersonName element in the xNL XML.
  19. * 'data' - Additional data for this address.
  20. *
  21. * Add the source field mappings to the argument array then add null mappings to
  22. * avoid having fields flagged as as unmapped:
  23. * @code
  24. * $arguments = array(
  25. * 'thoroughfare' => array('source_field' => 'profile_address'),
  26. * 'locality' => array('source_field' => 'profile_city'),
  27. * 'administrative_area' => array('source_field' => 'profile_state'),
  28. * );
  29. * // The country should be passed in as the primary value.
  30. * $this->addFieldMapping('field_user_address', 'profile_country')
  31. * ->arguments($arguments);
  32. * // Since the excerpt is mapped via an argument, add a null mapping so it's
  33. * // not flagged as unmapped.
  34. * $this->addFieldMapping(NULL, 'profile_address');
  35. * $this->addFieldMapping(NULL, 'profile_city');
  36. * $this->addFieldMapping(NULL, 'profile_state');
  37. * @endcode
  38. */
  39. class MigrateAddressFieldHandler extends MigrateFieldHandler {
  40. public function __construct() {
  41. $this->registerTypes(array('addressfield'));
  42. }
  43. public function prepare($entity, array $field_info, array $instance, array $values) {
  44. $arguments = array();
  45. if (isset($values['arguments'])) {
  46. $arguments = array_filter($values['arguments']);
  47. unset($values['arguments']);
  48. }
  49. $language = $this->getFieldLanguage($entity, $field_info, $arguments);
  50. // Setup the standard Field API array for saving.
  51. $delta = 0;
  52. foreach ($values as $value) {
  53. $return[$language][$delta] = array('country' => $value) + array_intersect_key($arguments, $field_info['columns']);
  54. $delta++;
  55. }
  56. return isset($return) ? $return : NULL;
  57. }
  58. }