You are here

public function MigrateTermNodeHandler::prepare in Migrate 6.2

File

plugins/destinations/term.inc, line 276
Support for taxonomy term destinations.

Class

MigrateTermNodeHandler
Handler to process term assignments for nodes

Code

public function prepare(stdClass $node, stdClass $row) {

  // Identify vocabularies for this node type
  $vocabs = taxonomy_get_vocabularies($node->type);
  foreach ($vocabs as $vid => $vocab) {
    $vocab_name = $vocab->name;
    if (isset($node->{$vocab_name})) {
      $vocab_values = $node->{$vocab_name};
      if (!is_array($vocab_values)) {
        $vocab_values = array(
          $vocab_values,
        );
      }
      $by_tid = FALSE;
      if (isset($vocab_values['arguments']['source_type'])) {
        if ($vocab_values['arguments']['source_type'] == 'tid') {
          $by_tid = TRUE;
        }
      }
      unset($vocab_values['arguments']);
      foreach ($vocab_values as $term_value) {
        if ($by_tid) {
          $node->taxonomy[$term_value] = $term_value;
        }
        else {
          foreach (taxonomy_get_term_by_name($term_value) as $term) {
            if ($term->vid == $vid) {
              $node->taxonomy[$term->tid] = $term->tid;
            }
          }
        }
      }
    }
  }
}