video_embed_field.feeds.inc 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /**
  3. * @file
  4. * On behalf implementation of Feeds mapping API for video_embed_field.module.
  5. */
  6. /**
  7. * Implements hook_feeds_processor_targets_alter().
  8. *
  9. * @see FeedsNodeProcessor::getMappingTargets().
  10. */
  11. function video_embed_field_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_name) {
  12. foreach (field_info_instances($entity_type, $bundle_name) as $name => $instance) {
  13. $info = field_info_field($name);
  14. if ($info['type'] == 'video_embed_field') {
  15. $targets[$name] = array(
  16. 'name' => $instance['label'],
  17. 'callback' => 'video_embed_field_set_target',
  18. 'description' => t('The @label field of the node.', array('@label' => $instance['label'])),
  19. );
  20. }
  21. }
  22. }
  23. /**
  24. * Callback for mapping. Here is where the actual mapping happens.
  25. *
  26. * When the callback is invoked, $target contains the name of the field the
  27. * user has decided to map to and $value contains the value of the feed item
  28. * element the user has picked as a source.
  29. */
  30. function video_embed_field_set_target($source, $entity, $target, $value) {
  31. if (empty($value)) {
  32. return;
  33. }
  34. $field = isset($entity->$target) ? $entity->$target : array();
  35. if (!is_array($value) && !is_object($value)) {
  36. $field['und'][0]['video_url'] = $value;
  37. }
  38. $entity->{$target} = $field;
  39. }