function taxonomy_feeds_set_target in Feeds 7
Same name and namespace in other branches
- 8.2 mappers/taxonomy.inc \taxonomy_feeds_set_target()
- 6 mappers/taxonomy.inc \taxonomy_feeds_set_target()
- 7.2 mappers/taxonomy.inc \taxonomy_feeds_set_target()
Callback for mapping. Here is where the actual mapping happens.
@todo Do not create new terms for non-autotag fields.
1 string reference to 'taxonomy_feeds_set_target'
- taxonomy_feeds_processor_targets_alter in mappers/
taxonomy.inc - Implements hook_feeds_processor_targets_alter().
File
- mappers/
taxonomy.inc, line 62 - Mapper that exposes a node's taxonomy vocabularies as mapping targets.
Code
function taxonomy_feeds_set_target($entity, $target, $terms) {
if (empty($terms)) {
return;
}
// Handle non-multiple values.
if (!is_array($terms)) {
$terms = array(
$terms,
);
}
$info = field_info_field($target);
// See http://drupal.org/node/881530
if (isset($info['settings']['allowed_values'][0]['vocabulary'])) {
$vocabulary = taxonomy_vocabulary_machine_name_load($info['settings']['allowed_values'][0]['vocabulary']);
}
else {
$vocabulary = taxonomy_vocabulary_load($info['settings']['allowed_values'][0]['vid']);
}
$i = 0;
$entity->{$target} = isset($entity->{$target}) ? $entity->{$target} : array();
foreach ($terms as $term) {
$tid = 0;
if ($term instanceof FeedsTermElement) {
$tid = $term->tid;
}
elseif (is_numeric($term)) {
$tid = $term;
}
elseif (is_string($term)) {
$tid = taxonomy_term_check_term($term, $vocabulary->vid);
}
if ($tid) {
$entity->{$target}['und'][$i]['tid'] = $tid;
}
if ($info['cardinality'] == 1) {
break;
}
$i++;
}
}