cck_phone.inc 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * Primary value passed to this field must be the two letter ISO country code of
  4. * the phone number.
  5. *
  6. * Subfields are used to specify all the other values:
  7. * 'number' - The actual phone number.
  8. * 'extension' - The extension.
  9. *
  10. * @code
  11. * // The country should be passed in as the primary value.
  12. * $this->addFieldMapping('field_user_phone', 'profile_country');
  13. * $this->addFieldMapping('field_user_phone:number', 'profile_number');
  14. * $this->addFieldMapping('field_user_phone:extension', 'profile_extension');
  15. * @endcode
  16. */
  17. class MigrateCckPhoneHandler extends MigrateFieldHandler {
  18. public function __construct() {
  19. $this->registerTypes(array('phone_number'));
  20. }
  21. public function fields($type) {
  22. return array(
  23. 'number' => t('Subfield: The phone number itself'),
  24. 'extension' => t('Extension: An optional extension'),
  25. );
  26. }
  27. public function prepare($entity, array $field_info, array $instance, array $values) {
  28. $arguments = array();
  29. if (isset($values['arguments'])) {
  30. $arguments = array_filter($values['arguments']);
  31. unset($values['arguments']);
  32. }
  33. $language = $this->getFieldLanguage($entity, $field_info, $arguments);
  34. // Setup the standard Field API array for saving.
  35. $delta = 0;
  36. foreach ($values as $value) {
  37. $return[$language][$delta] = array('country_codes' => drupal_strtolower($value));
  38. if (isset($arguments['number'])) {
  39. if (is_array($arguments['number'])) {
  40. $return[$language][$delta]['number'] = $arguments['number'][$delta];
  41. }
  42. else {
  43. $return[$language][$delta]['number'] = $arguments['number'];
  44. }
  45. }
  46. if (isset($arguments['extension'])) {
  47. if (is_array($arguments['extension'])) {
  48. $return[$language][$delta]['extension'] = $arguments['extension'][$delta];
  49. }
  50. else {
  51. $return[$language][$delta]['extension'] = $arguments['extension'];
  52. }
  53. }
  54. $delta++;
  55. }
  56. return isset($return) ? $return : NULL;
  57. }
  58. }