You are here

function link_feeds_set_target in Feeds 7

Same name and namespace in other branches
  1. 8.2 mappers/link.inc \link_feeds_set_target()
  2. 6 mappers/link.inc \link_feeds_set_target()
  3. 7.2 mappers/link.inc \link_feeds_set_target()

Callback for mapping to link field.

Parameters

$node: Reference to the node object we are working on.

$target: The selected link CCK field.

$value: The value to assign to the CCK field.

1 string reference to 'link_feeds_set_target'
link_feeds_node_processor_targets_alter in mappers/link.inc
Implements hook_feeds_node_processor_targets_alter().

File

mappers/link.inc, line 51
On behalf implementation of Feeds mapping API for link.module (CCK).

Code

function link_feeds_set_target($node, $target, $value) {
  module_load_include('inc', 'link');
  if (!empty($value)) {
    static $defaults = array();
    list($field_name, $sub_field) = split(':', $target);
    if (!isset($defaults[$node->type][$field_name])) {
      $field = content_fields($field_name, $node->type);
      $defaults[$node->type][$field_name]['attributes'] = $field['attributes'];
      if (!in_array($field['title'], array(
        'optional',
        'required',
        'none',
      ))) {
        $defaults[$node->type][$field_name]['title'] = $field['title_value'];
      }
    }
    $field_data = isset($node->{$field_name}) ? $node->{$field_name} : array();
    if (!is_array($value)) {
      $value = array(
        $value,
      );
    }
    $i = 0;
    foreach ($value as $v) {
      if ($v instanceof FeedsEnclosure) {
        $v = $v
          ->getValue();
      }
      if (!isset($field_data[$i])) {
        $field_data[$i] = $defaults[$node->type][$field_name];
      }
      if ($sub_field != 'url' || ($v = link_cleanup_url($v)) && valid_url($v, true)) {
        $field_data[$i][$sub_field] = $v;
      }
      $i++;
    }
    $node->{$field_name} = $field_data;
  }
}