function migrate_example_wine_categories in Migrate 7.2
Same name and namespace in other branches
- 6.2 migrate_example/wine.install.inc \migrate_example_wine_categories()
1 call to migrate_example_wine_categories()
- migrate_example_wine_install in migrate_example/
wine.install.inc
3 string references to 'migrate_example_wine_categories'
- MigrateNodeUnitTest::testNodeImport in tests/
plugins/ destinations/ node.test - MigrateTaxonomyUnitTest::testTermImport in tests/
plugins/ destinations/ term.test - WineWineMigration::__construct in migrate_example/
wine.inc - General initialization of a Migration object.
File
- migrate_example/
wine.install.inc, line 671 - Set up for the wine (advanced) example.
Code
function migrate_example_wine_categories() {
// Create vocabularies for variety, region, and "best with"
$description = st('Wine varieties');
$help = st('Select the variety of this wine');
$vocabulary = (object) array(
'name' => 'Migrate Example Wine Varieties',
'description' => $description,
'machine_name' => 'migrate_example_wine_varieties',
'help' => $help,
);
taxonomy_vocabulary_save($vocabulary);
if (!field_info_field('migrate_example_wine_varieties')) {
$field = array(
'field_name' => $vocabulary->machine_name,
'type' => 'taxonomy_term_reference',
'cardinality' => 1,
'settings' => array(
'allowed_values' => array(
array(
'vocabulary' => $vocabulary->machine_name,
'vid' => $vocabulary->vid,
'parent' => 0,
),
),
),
);
field_create_field($field);
}
if (!field_info_instance('node', 'migrate_example_wine_varieties', 'migrate_example_wine')) {
$instance = array(
'field_name' => $vocabulary->machine_name,
'entity_type' => 'node',
'label' => $vocabulary->name,
'bundle' => 'migrate_example_wine',
'description' => $vocabulary->help,
'widget' => array(
'type' => 'taxonomy_autocomplete',
),
);
field_create_instance($instance);
}
$description = st('Wine regions');
$help = st('Select the region this wine comes from');
$vocabulary = (object) array(
'name' => 'Migrate Example Wine Regions',
'description' => $description,
'machine_name' => 'migrate_example_wine_regions',
'help' => $help,
);
taxonomy_vocabulary_save($vocabulary);
if (!field_info_field('migrate_example_wine_regions')) {
$field = array(
'field_name' => $vocabulary->machine_name,
'type' => 'taxonomy_term_reference',
'cardinality' => 1,
'settings' => array(
'allowed_values' => array(
array(
'vocabulary' => $vocabulary->machine_name,
'vid' => $vocabulary->vid,
'parent' => 0,
),
),
),
);
field_create_field($field);
}
if (!field_info_instance('node', 'migrate_example_wine_regions', 'migrate_example_wine')) {
$instance = array(
'field_name' => $vocabulary->machine_name,
'entity_type' => 'node',
'label' => $vocabulary->name,
'bundle' => 'migrate_example_wine',
'description' => $vocabulary->help,
'widget' => array(
'type' => 'taxonomy_autocomplete',
),
);
field_create_instance($instance);
}
if (!field_info_instance('node', 'migrate_example_wine_regions', 'migrate_example_producer')) {
$instance = array(
'field_name' => $vocabulary->machine_name,
'entity_type' => 'node',
'label' => $vocabulary->name,
'bundle' => 'migrate_example_producer',
'description' => $vocabulary->help,
'widget' => array(
'type' => 'taxonomy_autocomplete',
),
);
field_create_instance($instance);
}
$description = st('Foods the wine goes best with');
$help = st('Enter any foods this wine may be paired with, separated by commas');
$vocabulary = (object) array(
'name' => 'Migrate Example Wine Best With',
'description' => $description,
'machine_name' => 'migrate_example_wine_best_with',
'help' => $help,
);
taxonomy_vocabulary_save($vocabulary);
if (!field_info_field('migrate_example_wine_best_with')) {
$field = array(
'field_name' => $vocabulary->machine_name,
'type' => 'taxonomy_term_reference',
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
'settings' => array(
'allowed_values' => array(
array(
'vocabulary' => $vocabulary->machine_name,
'vid' => $vocabulary->vid,
'parent' => 0,
),
),
),
);
field_create_field($field);
}
if (!field_info_instance('node', 'migrate_example_wine_best_with', 'migrate_example_wine')) {
$instance = array(
'field_name' => $vocabulary->machine_name,
'entity_type' => 'node',
'label' => $vocabulary->name,
'bundle' => 'migrate_example_wine',
'description' => $vocabulary->help,
'widget' => array(
'type' => 'taxonomy_autocomplete',
),
);
field_create_instance($instance);
}
}