You are here

class MigrateTermNodeHandler in Migrate 6.2

Handler to process term assignments for nodes

Hierarchy

Expanded class hierarchy of MigrateTermNodeHandler

1 string reference to 'MigrateTermNodeHandler'
migrate_migrate_api in ./migrate.module

File

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

View source
class MigrateTermNodeHandler extends MigrateDestinationHandler {
  public function __construct() {
    $this
      ->registerTypes(array(
      'node',
    ));
  }
  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;
              }
            }
          }
        }
      }
    }
  }

  /*
   * @param
   *   Can be 'tid'. Otherwise, 'name' is assumed.
   */
  static function arguments($source_type = NULL) {
    return get_defined_vars();
  }
  public function fields($entity_type, $bundle) {
    $fields = array();
    $vocabs = taxonomy_get_vocabularies($bundle);
    foreach ($vocabs as $vid => $vocab) {
      $vocab_name = $vocab->name;
      $fields[$vocab_name] = $vocab_name;
    }
    return $fields;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MigrateHandler::$dependencies protected property List of other handler classes which should be invoked before the current one.
MigrateHandler::$typesHandled protected property List of "types" handled by this handler. Depending on the kind of handler, these may be destination types, field types, etc.
MigrateHandler::getDependencies public function
MigrateHandler::getTypesHandled public function
MigrateHandler::handlesType public function Does this handler handle the given type?
MigrateHandler::registerTypes protected function Register a list of types handled by this class
MigrateTermNodeHandler::arguments static function
MigrateTermNodeHandler::fields public function
MigrateTermNodeHandler::prepare public function
MigrateTermNodeHandler::__construct public function Overrides MigrateHandler::__construct