function youtube_set_target in YouTube Field 7
Callback to set the Feeds target for a YouTube field.
Parameters
FeedsSource $source: Field mapper source settings.
object $entity: An entity object, for instance a node object.
string $target: A string identifying the target on the node.
string|array $value: The value to populate the target with.
array $mapping: Associative array of the mapping settings from the per mapping configuration form.
1 string reference to 'youtube_set_target'
- youtube_feeds_processor_targets_alter in ./
youtube.inc - Implements hook_feeds_processor_targets_alter().
File
- ./
youtube.inc, line 297 - YouTube field helper functions.
Code
function youtube_set_target(FeedsSource $source, $entity, $target, $value, array $mapping) {
if (empty($value)) {
return;
}
if (!is_array($value)) {
$value = array(
$value,
);
}
$info = field_info_field($target);
$field = isset($entity->{$target}) ? $entity->{$target} : array(
LANGUAGE_NONE => array(),
);
// Allow for mappings to a multi-value field on the same target.
$delta = count($field[LANGUAGE_NONE]);
foreach ($value as $v) {
if ($info['cardinality'] == $delta) {
break;
}
if (is_object($v) && $v instanceof FeedsElement) {
$v = $v
->getValue();
}
if (is_scalar($v)) {
$video_id = youtube_get_video_id($v);
if ($video_id) {
$entity->{$target}[LANGUAGE_NONE][$delta] = array(
'input' => $v,
'video_id' => $video_id,
);
$delta++;
}
}
}
}