function location_taxonomize_initialize in Location Taxonomize 7.2
Same name and namespace in other branches
- 7 location_taxonomize.module \location_taxonomize_initialize()
Submit callback for the initialization config form. Handles initialization of Location Taxonomy.
1 string reference to 'location_taxonomize_initialize'
- location_taxonomize_form in ./
location_taxonomize.admin.inc - Location Taxonomize administration form
File
- ./
location_taxonomize.module, line 73
Code
function location_taxonomize_initialize($form, $form_state) {
$values_init = $form_state['values']['location_taxonomize_vocab'];
$method = $values_init['method'];
switch ($method) {
case 'new':
// create a new location vocabulary
taxonomy_vocabulary_save((object) array(
'name' => t('Location'),
'machine_name' => LT_VOCAB_NAME,
'description' => t('This vocabulary is synchronized with Location data automatically by the @name module', array(
'@name' => LT_MODULE_NAME,
)),
));
// save the vid of the newly created vocabulary
$vocab = taxonomy_vocabulary_machine_name_load(LT_VOCAB_NAME);
$vid = $vocab->vid;
variable_set('location_taxonomize_vid', $vid);
$msg = t('Successfully created the Location taxonomy (vid @vid)', array(
'@vid' => $vid,
));
break;
case 'existing':
// save the vid of the existing vocabulary
$vid = $values_init['possible_vid'];
variable_set('location_taxonomize_vid', $vid);
$msg = t('Successfully connected to the existing Location Vocabulary (vid @vid)', array(
'@vid' => $vid,
));
break;
}
drupal_set_message($msg);
// Create the 'taxonomy_longname' field if it doesn't already exist.
if (!field_info_field('location_taxonomize_longname')) {
$field = array(
'field_name' => 'location_taxonomize_longname',
'type' => 'text',
);
field_create_field($field);
}
// Create the instance on the bundle.
if (!field_info_instance('taxonomy_term', 'location_taxonomize_longname', 'location_taxonomize')) {
$instance = array(
'field_name' => 'location_taxonomize_longname',
'label' => t('Long Name'),
'entity_type' => 'taxonomy_term',
'bundle' => 'location_taxonomize',
);
field_create_instance($instance);
}
// set defaults for longname fields
_location_taxonomize_init_var_longname();
// Allow modules to hook into the initialization process.
$settings = array(
'source' => $values_init['source'],
'method' => $values_init['method'],
'hierarchy' => $values_init['hierarchy'],
);
module_invoke_all('location_taxonomize_initialize', $settings);
drupal_set_message(t('Location Taxonomize initialized successfully'));
}