diff --git a/includes/simplenews.admin.inc b/includes/simplenews.admin.inc index 1dd1161..2be7e87 100644 --- a/includes/simplenews.admin.inc +++ b/includes/simplenews.admin.inc @@ -633,7 +633,8 @@ function simplenews_admin_category_form_submit($form, &$form_state) { // Create or update taxonomy term. $term = new stdClass(); $term->tid = $form_state['values']['tid']; - $term->vid = variable_get('simplenews_vid', 0); + $term->vocabulary_machine_name = 'newsletter'; + $term->vid = taxonomy_vocabulary_machine_name_load('newsletter')->vid; $term->name = $form_state['values']['name']; $term->description = $form_state['values']['description']; $term->weight = $form_state['values']['weight']; diff --git a/simplenews.module b/simplenews.module index 0afff69..65b1e23 100644 --- a/simplenews.module +++ b/simplenews.module @@ -717,7 +717,7 @@ function simplenews_form_node_type_form_alter(&$form, $form_state) { */ function simplenews_form_taxonomy_form_term_alter(&$form, $form_state) { if (isset($form_state['confirm_delete']) && $form_state['confirm_delete']) { - if ($form['#term']->vid == variable_get('simplenews_vid', 0)) { + if ($form['#term']->vocabulary_machine_name == 'newsletter') { $category = simplenews_category_load($form['#term']->tid); $form['description']['#markup'] = '

' . t('This taxonomy term is part of simplenews newsletter category %category_name. Deleting this term will delete the newsletter category and all subscriptions to category %category_name. This action cannot be undone.', array('%category_name' => _simplenews_newsletter_name($category))) . '

' . $form['description']['#markup']; } @@ -733,7 +733,7 @@ function simplenews_taxonomy_term_delete($term) { // A simplenews newsletter category can not exist without the associated // taxonomy term. So we delete the category. simplenews_category_delete() // will also delete the subscriptions to the category. - if ($term->vid == variable_get('simplenews_vid', 0)) { + if ($term->vocabulary_machine_name == 'newsletter') { // Make sure we only try to delete if not already deleted. if (($category = simplenews_category_load($term->tid)) !== FALSE) { // Add name and description from $term object. diff --git a/tests/simplenews.test b/tests/simplenews.test index b4c85ac..da6b336 100644 --- a/tests/simplenews.test +++ b/tests/simplenews.test @@ -80,7 +80,8 @@ class SimplenewsTestCase extends DrupalWebTestCase { * @return newsletter tid. */ function getRandomNewsletter() { - if ($taxonomies = taxonomy_get_tree(variable_get('simplenews_vid', ''))) { + $vid = db_query('SELECT vid FROM {taxonomy_vocabulary} WHERE machine_name = :name', array(':name' => 'newsletter'))->fetchField(); + if ($taxonomies = taxonomy_get_tree($vid)) { $tids = array(); foreach ($taxonomies as $newsletter) { $tids[] = $newsletter->tid; @@ -1676,7 +1677,7 @@ class SimpleNewsI18nTestCase extends SimplenewsTestCase { ); $this->drupalPost('admin/config/regional/i18n/strings', $edit, t('Save configuration')); - $vocabulary = taxonomy_vocabulary_load(variable_get('simplenews_vid', 0)); + $vocabulary = taxonomy_vocabulary_machine_name_load('newsletter'); $vocabulary->i18n_mode = I18N_MODE_LOCALIZE; taxonomy_vocabulary_save($vocabulary); drupal_static_reset('i18n_taxonomy_vocabulary_mode'); @@ -1715,7 +1716,7 @@ class SimpleNewsI18nTestCase extends SimplenewsTestCase { simplenews_subscribe_user($spanish_mail, $tid, FALSE, 'spanish', 'es'); // Translate category. - $vocabulary = taxonomy_vocabulary_load(variable_get('simplenews_vid', 0)); + $vocabulary = taxonomy_vocabulary_machine_name_load('newsletter'); $vocabulary->i18n_mode = I18N_MODE_LOCALIZE; taxonomy_vocabulary_save($vocabulary); drupal_static_reset('i18n_taxonomy_vocabulary_mode'); @@ -1919,6 +1920,14 @@ class SimpleNewsUpgradePathTestCase extends UpgradePathTestCase { // $this->assertEqual('simplenews_test', $mails[0]['id']); // $this->assertEqual('user@example.com', $mails[0]['to']); // $this->assertEqual(t('[Drupal newsletter] @title', array('@title' => $edit['title'])), $mails[0]['subject']); + + // Make sure that new categories can be created. + $edit = array( + 'name' => $this->randomName(), + ); + $this->drupalPost('admin/config/services/simplenews/add', $edit, t('Save')); + $this->assertResponse(200); + $this->assertText($edit['name']); } }