class MigrateTermNodeHandler in Migrate 6.2
Handler to process term assignments for nodes
Hierarchy
- class \MigrateHandler
- class \MigrateDestinationHandler
- class \MigrateTermNodeHandler
- class \MigrateDestinationHandler
Expanded class hierarchy of MigrateTermNodeHandler
1 string reference to 'MigrateTermNodeHandler'
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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MigrateHandler:: |
protected | property | List of other handler classes which should be invoked before the current one. | |
MigrateHandler:: |
protected | property | List of "types" handled by this handler. Depending on the kind of handler, these may be destination types, field types, etc. | |
MigrateHandler:: |
public | function | ||
MigrateHandler:: |
public | function | ||
MigrateHandler:: |
public | function | Does this handler handle the given type? | |
MigrateHandler:: |
protected | function | Register a list of types handled by this class | |
MigrateTermNodeHandler:: |
static | function | ||
MigrateTermNodeHandler:: |
public | function | ||
MigrateTermNodeHandler:: |
public | function | ||
MigrateTermNodeHandler:: |
public | function |
Overrides MigrateHandler:: |