Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. <?php
  2. /**
  3. * @file
  4. * Implements Feeds support for telephone fields.
  5. */
  6.  
  7. /**
  8. * Implements hook_feeds_processor_targets_alter().
  9. *
  10. * @see FeedsNodeProcessor::getMappingTargets().
  11. */
  12. function telephone_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_name) {
  13. foreach (field_info_instances($entity_type, $bundle_name) as $name => $instance) {
  14. $info = field_info_field($name);
  15.  
  16. if ($info['type'] == 'telephone') {
  17. $targets[$name] = array(
  18. 'name' => check_plain($instance['label']),
  19. 'callback' => 'telephone_feeds_set_target',
  20. 'description' => t('The @label field of the node.', array('@label' => $instance['label'])),
  21. );
  22. }
  23. }
  24. }
  25.  
  26. /**
  27. * Callback for mapping telephone fields.
  28. */
  29. function telephone_feeds_set_target(FeedsSource $source, $entity, $target, array $values) {
  30. // Iterate over all values.
  31. $field = isset($entity->$target) ? $entity->$target : array('und' => array());
  32.  
  33. foreach ($values as $value) {
  34.  
  35. if (is_object($value) && ($value instanceof FeedsElement)) {
  36. $value = $value->getValue();
  37. }
  38.  
  39. if (is_scalar($value) && strlen($value)) {
  40. $field['und'][] = array('value' => $value);
  41. }
  42. }
  43.  
  44. $entity->{$target} = $field;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement