class KickstartMigrateTaxonomyTermReferenceFieldHandler in Commerce Kickstart 7.2
Hierarchy
- class \MigrateHandler
Expanded class hierarchy of KickstartMigrateTaxonomyTermReferenceFieldHandler
1 string reference to 'KickstartMigrateTaxonomyTermReferenceFieldHandler'
- commerce_kickstart_migrate_migrate_api in modules/
commerce_kickstart/ commerce_kickstart_migrate/ commerce_kickstart_migrate.module - Implements hook_migrate_api().
File
- modules/
commerce_kickstart/ commerce_kickstart_migrate/ plugins/ destinations/ fields.inc, line 4
View source
class KickstartMigrateTaxonomyTermReferenceFieldHandler extends MigrateTaxonomyTermReferenceFieldHandler {
public function __construct() {
$this
->registerTypes(array(
'taxonomy_term_reference',
));
}
public function fields($type, $instance, $migration = NULL) {
return array(
'additional_field' => t('Option: Pass any additional field that should be added in the term. Array should be "field_name|value".'),
'weight' => t('Option: Pass term weight. Value should be "weight".'),
);
}
public function prepare($entity, array $field_info, array $instance, array $values) {
if (isset($values['arguments'])) {
$arguments = $values['arguments'];
unset($values['arguments']);
}
else {
$arguments = array();
}
if (empty($values[0])) {
$values = array();
}
if ($values) {
// Get the vocabulary for this term
if (isset($field_info['settings']['allowed_values'][0]['vid'])) {
$vid = $field_info['settings']['allowed_values'][0]['vid'];
}
else {
$vocab_name = $field_info['settings']['allowed_values'][0]['vocabulary'];
$names = taxonomy_vocabulary_get_names();
$vid = $names[$vocab_name]->vid;
}
// Cannot use taxonomy_term_load_multiple() since we have an array of names.
// It wants a singular value. This query may return case-insensitive
// matches.
$existing_terms = db_select('taxonomy_term_data', 'td')
->fields('td', array(
'tid',
'name',
))
->condition('td.name', $values, 'IN')
->condition('td.vid', $vid)
->execute()
->fetchAllKeyed(1, 0);
foreach ($values as $value) {
if (isset($existing_terms[$value])) {
$tids[] = $existing_terms[$value];
}
elseif (!empty($arguments['create_term'])) {
$new_term = new stdClass();
$new_term->vid = $vid;
$new_term->name = $value;
if (!empty($arguments['weight'])) {
$new_term->weight = $arguments['weight'];
}
if (!empty($arguments['additional_field'])) {
$additional_field = explode('|', $arguments['additional_field']);
$additional_field_machine_name = $additional_field[0];
$additional_field_value = $additional_field[1];
$new_term->{$additional_field_machine_name}[LANGUAGE_NONE][]['value'] = $additional_field_value;
}
taxonomy_term_save($new_term);
}
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
KickstartMigrateTaxonomyTermReferenceFieldHandler:: |
public | function |
Implementation of MigrateFieldHandler::fields(). Overrides MigrateTaxonomyTermReferenceFieldHandler:: |
|
KickstartMigrateTaxonomyTermReferenceFieldHandler:: |
public | function |
Overrides MigrateTaxonomyTermReferenceFieldHandler:: |
|
KickstartMigrateTaxonomyTermReferenceFieldHandler:: |
public | function |
Overrides MigrateTaxonomyTermReferenceFieldHandler:: |
|
MigrateFieldHandler:: |
function | Determine the language of the field. | ||
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? | 1 |
MigrateHandler:: |
protected | function | Register a list of types handled by this class |