name.inc 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * Primary value passed to this field must be the 'given' name.
  4. * it cannot be NULL, but may be an empty string.
  5. *
  6. * Arguments are used to specify all the other values:
  7. * 'title' => array('source_field' => 'title'),
  8. * 'middle' => array('source_field' => 'middle'),
  9. * 'family' => array('source_field' => 'family'),
  10. * 'generational' => array('source_field' => 'generational'),
  11. * 'credentials' => array('source_field' => 'credentials'),
  12. *
  13. * Add the source field mappings to the argument array then add null mappings to
  14. * avoid having fields flagged as as unmapped:
  15. * @code
  16. * $arguments = array(
  17. * 'title' => array('source_field' => 'profile_title'),
  18. * 'middle' => array('source_field' => 'profile_middle_name'),
  19. * 'family' => array('source_field' => 'profile_last_name'),
  20. * );
  21. * // The given name should be passed in as the primary value.
  22. * $this->addFieldMapping('field_name', 'profile_first_name')
  23. * ->arguments($arguments);
  24. * // Since the excerpt is mapped via an argument, add a null mapping so it's
  25. * // not flagged as unmapped.
  26. * $this->addFieldMapping(NULL, 'profile_title');
  27. * $this->addFieldMapping(NULL, 'profile_middle_name');
  28. * $this->addFieldMapping(NULL, 'profile_last_name');
  29. * @endcode
  30. */
  31. class MigrateNameHandler extends MigrateFieldHandler {
  32. public function __construct() {
  33. $this->registerTypes(array('name'));
  34. }
  35. public function prepare($entity, array $field_info, array $instance, array $values) {
  36. $arguments = array();
  37. if (isset($values['arguments'])) {
  38. $arguments = array_filter($values['arguments']);
  39. unset($values['arguments']);
  40. }
  41. $language = $this->getFieldLanguage($entity, $field_info, $arguments);
  42. // Setup the standard Field API array for saving.
  43. $delta = 0;
  44. foreach ($values as $value) {
  45. $return[$language][$delta] = array('given' => $value) + array_intersect_key($arguments, $field_info['columns']);
  46. $delta++;
  47. }
  48. return isset($return) ? $return : NULL;
  49. }
  50. }