You are here

function primary_term_node_import_values_alter in Node import 6

Implementation of hook_node_import_values_alter().

File

supported/primary_term/primary_term.inc, line 97
Support file for the primary term module.

Code

function primary_term_node_import_values_alter(&$values, $type, $defaults, $options, $fields, $preview) {
  if (($node_type = node_import_type_is_node($type)) !== FALSE) {
    $taxonomy = isset($values['primary_term']) ? $values['primary_term'] : array();
    foreach ($fields as $fieldname => $fieldinfo) {
      if (strpos($fieldname, 'primary_term:') === 0) {
        $vocab = $fieldinfo['vocabulary'];
        if ($vocab->tags) {
          $taxonomy['tags'] = isset($taxonomy['tags']) ? $taxonomy['tags'] : array();
          $taxonomy['tags'][$vocab->vid] = implode(',', (array) $values[$fieldname]);
        }
        else {
          $taxonomy[$vocab->vid] = $values[$fieldname];
        }
        unset($values[$fieldname]);
      }
    }

    /*
    the primary term module uses node->primary_term and node->primaryterm for
    different purposes, mostly for historical reasons, as changing this would
    break compatibility with every contributed module that uses this field
    (cf. comments in primary_term.module)
    */
    $values['primary_term'] = $taxonomy;
    $tid = array_shift($taxonomy);
    $values['primaryterm'] = $tid;
  }
}