You are here

function file_feeds_atom_set_target_element_value_alter in Feeds Atom 7

@todo, update this for D7

Implementation of hook_feeds_atom_rdf_map_alter().

We implement this hook on behalf of the taxonomy module so that we can lazy-create terms as needed. We only do so if the vocabulary the term is in already exists. If the vocabulary doesn't exist, the incoming term is ignored.

Parameters

$target_item: The node that we are creating/editing.

$source_item: The parsed data array from the feed.

Return value

unknown_type / function taxonomy_feeds_atom_rdf_map_alter(&$target_item, $source_item) {

// @todo Check for consistency in taxonomy and taxonomy_vocabulary. // The coder module made automatic changes in the D6 to D7 update.

if (empty($source_item['rdf']['taxonomy']) || !is_array($source_item['rdf']['taxonomy'])) { // Nothing to process return; }

// Zero out the taxonomy data that is already there, as it will break if we // try to save the node with it there. $target_item->taxonomy = array();

// Process the term data. foreach ($source_item['rdf']['taxonomy'] as $source_term) { // Add new terms if they don't exist $vid = NULL; $tid = NULL;

// Find the vocabulary. if (!empty($source_term['taxonomy_vocabulary'])) { // Features intergration: Features stores vocabulary machine name's in // module key prepended with features_ if (module_exists('features')) { $machine_name = !empty($source_term['machine']) ? $source_term['machine'] : $source_term['taxonomy_vocabulary']; // Add in features_ if doesn't exist if (strpos($machine_name, 'features_') !== 0) { $machine_name = 'features_' . $machine_name; } $vid = db_query("SELECT vid FROM {taxonomy_vocabulary} WHERE module = :module", array(':module' => strtolower($machine_name)))->fetchField(); } // Fallback to name matching if vid not found above. if (empty($vid)) { $vid = db_query("SELECT vid FROM {taxonomy_vocabulary} WHERE lower(name) = :lower(name)", array(':lower(name)' => strtolower($source_term['taxonomy_vocabulary'])))->fetchField(); } }

// See if the term already exists foreach (taxonomy_get_term_by_name($source_term['title']) as $term) { // if VID was not found but name matches or vid is term's vocabulary. if (empty($vid) || $vid == $term->vid) { $tid = $term->tid; } } // Create the new term if doesn't exist and know vocabulary if (empty($tid) && !empty($vid)) { $new_term = array( 'vid' => $vid, 'name' => $source_term['title'], 'description' => $source_term['description'], ); taxonomy_term_save($term /* @todo Term object replaces array $new_term * /); $tid = $new_term['tid']; }

// Apply the term to the target node. if (!empty($tid)) { $term = taxonomy_term_load($tid, TRUE); $target_item->taxonomy[$term->tid] = $term; } } }

Implementation of hook_feeds_atom_set_target_element_value_alter().

File

./feeds_atom.module, line 148
Contains the main functionality for feeds_atom.

Code

function file_feeds_atom_set_target_element_value_alter(&$value, $field_name) {
  _file_feeds_atom_set_target_element_value_alter($value, $field_name, $field_type = 'file');
}