function _simplenews_install_vocabulary in Simplenews 6
Same name and namespace in other branches
- 6.2 simplenews.install \_simplenews_install_vocabulary()
Create simplenews vocabulary and initial term.
1 call to _simplenews_install_vocabulary()
- simplenews_install in ./
simplenews.install - Implementation of hook_install().
File
- ./
simplenews.install, line 248 - Simplenews installation.
Code
function _simplenews_install_vocabulary() {
// Create the simplenews vocabulary. If it exists, set it as the simplenews_vid.
if ($vocabulary = db_fetch_array(db_query("SELECT * FROM {vocabulary} WHERE name = '%s'", t('Newsletter')))) {
$vocabulary['nodes'] = variable_get('simplenews_content_types', array(
'simplenews' => 'simplenews',
));
}
else {
$vocabulary = array(
'name' => t('Newsletter'),
'multiple' => '0',
'required' => '1',
'hierarchy' => '0',
'relations' => '0',
'module' => 'simplenews',
'nodes' => variable_get('simplenews_content_types', array(
'simplenews' => 'simplenews',
)),
);
}
taxonomy_save_vocabulary($vocabulary);
variable_set('simplenews_vid', $vocabulary['vid']);
// Check to see if at least 1 term exists, else create one
$tid = db_result(db_query('SELECT tid FROM {term_data} WHERE vid = %d', $vocabulary['vid']));
if (!$tid) {
$form_values = array(
'name' => t('@site_name newsletter', array(
'@site_name' => variable_get('site_name', 'Drupal'),
)),
'vid' => $vocabulary['vid'],
'weight' => 0,
);
switch (taxonomy_save_term($form_values)) {
case SAVED_UPDATED:
drupal_set_message(t('Updated term %name.', array(
'%name' => $form_values['name'],
)));
break;
case SAVED_DELETED:
drupal_set_message(t('Deleted term %name.', array(
'%name' => $form_values['name'],
)));
break;
}
}
}