function instagram_feeds_plugins_file_feeds_set_target in Instagram Feeds 7
Callback for mapping. Here is where the actual mapping happens.
When the callback is invoked, $target contains the name of the field the user has decided to map to and $value contains the value of the feed item element the user has picked as a source.
1 string reference to 'instagram_feeds_plugins_file_feeds_set_target'
- instagram_feeds_plugins_feeds_processor_targets_alter in modules/
instagram_feeds_plugins/ instagram_feeds_plugins.module - Implements hook_feeds_processor_targets_alter().
File
- modules/
instagram_feeds_plugins/ instagram_feeds_plugins.module, line 104 - Code for the Instagram Feeds Plugin module.
Code
function instagram_feeds_plugins_file_feeds_set_target($source, $entity, $target, $value) {
if (empty($value)) {
return;
}
module_load_include('inc', 'file');
// Make sure $value is an array of objects of type FeedsEnclosure.
if (!is_array($value)) {
$value = array(
$value,
);
}
foreach ($value as $k => $v) {
if ('InstagramFeedsPluginsPager' == $source->importer->config['fetcher']['plugin_key']) {
if (!$v instanceof InstagramFeedsPluginsEnclosure) {
if (is_string($v)) {
$value[$k] = new InstagramFeedsPluginsEnclosure($v, 'application/octet-stream');
}
else {
unset($value[$k]);
}
}
}
else {
if (!$v instanceof FeedsEnclosure) {
if (is_string($v)) {
$value[$k] = new FeedsEnclosure($v, 'application/octet-stream');
}
else {
unset($value[$k]);
}
}
}
}
if (empty($value)) {
return;
}
// Determine file destination.
// @todo This needs review and debugging.
list($entity_id, $vid, $bundle_name) = entity_extract_ids($entity->feeds_item->entity_type, $entity);
unset($vid, $entity_id);
$instance_info = field_info_instance($entity->feeds_item->entity_type, $target, $bundle_name);
$info = field_info_field($target);
$data = array();
if (!empty($entity->uid)) {
$data[$entity->feeds_item->entity_type] = $entity;
}
$destination = file_field_widget_uri($info, $instance_info, $data);
// Populate entity.
$i = 0;
$field = isset($entity->{$target}) ? $entity->{$target} : array();
foreach ($value as $v) {
if ($file = $v
->getFile($destination)) {
$field[LANGUAGE_NONE][$i] = (array) $file;
// @todo: Figure out how to properly populate this field.
$field[LANGUAGE_NONE][$i]['display'] = 1;
if ($info['cardinality'] == 1) {
break;
}
$i++;
}
}
$entity->{$target} = $field;
}