You are here

function _simplenews_init_simplenews_vocabulary in Simplenews 7

Create simplenews vocabulary and initial term.

1 call to _simplenews_init_simplenews_vocabulary()
simplenews_install in ./simplenews.install
Implements hook_install().

File

./simplenews.install, line 391
Install, update and uninstall functions for the simplenews module

Code

function _simplenews_init_simplenews_vocabulary() {

  // Create the simplenews vocabulary. If it exists, set simplenews_vid variable.
  $vocabularies = taxonomy_vocabulary_load_multiple(array(), array(
    'machine_name' => 'newsletter',
  ));
  $vocabulary = reset($vocabularies);
  if (!$vocabulary) {
    $vocabulary = new stdClass();
    $vocabulary->name = t('Newsletter');
    $vocabulary->machine_name = 'newsletter';
    $vocabulary->description = t('Simplenews newsletter categories.');
    $vocabulary->weight = '0';
    $vocabulary->hierarchy = '0';
    $vocabulary->module = 'simplenews';
  }
  taxonomy_vocabulary_save($vocabulary);
  variable_set('simplenews_vid', $vocabulary->vid);

  // Create a newsletter taxonomy term if none exists.
  $tree = taxonomy_get_tree($vocabulary->vid);
  if (count($tree) == 0) {
    $term = new stdClass();
    $term->name = t('@site_name newsletter', array(
      '@site_name' => variable_get('site_name', 'Drupal'),
    ));
    $term->description = t('@site_name newsletter categories.', array(
      '@site_name' => variable_get('site_name', 'Drupal'),
    ));
    $term->vid = $vocabulary->vid;
    taxonomy_term_save($term);
  }
}