Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @file
- * Implements Feeds support for telephone fields.
- */
- /**
- * Implements hook_feeds_processor_targets_alter().
- *
- * @see FeedsNodeProcessor::getMappingTargets().
- */
- function telephone_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_name) {
- foreach (field_info_instances($entity_type, $bundle_name) as $name => $instance) {
- $info = field_info_field($name);
- if ($info['type'] == 'telephone') {
- $targets[$name] = array(
- 'name' => check_plain($instance['label']),
- 'callback' => 'telephone_feeds_set_target',
- 'description' => t('The @label field of the node.', array('@label' => $instance['label'])),
- );
- }
- }
- }
- /**
- * Callback for mapping telephone fields.
- */
- function telephone_feeds_set_target(FeedsSource $source, $entity, $target, array $values) {
- // Iterate over all values.
- $field = isset($entity->$target) ? $entity->$target : array('und' => array());
- foreach ($values as $value) {
- if (is_object($value) && ($value instanceof FeedsElement)) {
- $value = $value->getValue();
- }
- if (is_scalar($value) && strlen($value)) {
- $field['und'][] = array('value' => $value);
- }
- }
- $entity->{$target} = $field;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement