summaryrefslogtreecommitdiff
path: root/modules/taxonomy
diff options
context:
space:
mode:
Diffstat (limited to 'modules/taxonomy')
-rw-r--r--modules/taxonomy/taxonomy.install5
-rw-r--r--modules/taxonomy/taxonomy.module32
-rw-r--r--modules/taxonomy/taxonomy.test34
3 files changed, 67 insertions, 4 deletions
diff --git a/modules/taxonomy/taxonomy.install b/modules/taxonomy/taxonomy.install
index f28ffedf4..56b7e01c6 100644
--- a/modules/taxonomy/taxonomy.install
+++ b/modules/taxonomy/taxonomy.install
@@ -12,6 +12,11 @@ function taxonomy_uninstall() {
// Remove variables.
variable_del('taxonomy_override_selector');
variable_del('taxonomy_terms_per_page_admin');
+ // Remove taxonomy_term bundles.
+ $vocabularies = db_query("SELECT machine_name FROM {taxonomy_vocabulary}")->fetchCol();
+ foreach ($vocabularies as $vocabulary) {
+ field_attach_delete_bundle('taxonomy_term', $vocabulary);
+ }
}
/**
diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module
index 50d2fd608..dc2847d37 100644
--- a/modules/taxonomy/taxonomy.module
+++ b/modules/taxonomy/taxonomy.module
@@ -532,12 +532,35 @@ function taxonomy_check_vocabulary_hierarchy($vocabulary, $changed_term) {
}
/**
- * Save a term object to the database.
+ * Saves a term object to the database.
*
* @param $term
- * A term object.
+ * The taxonomy term object with the following properties:
+ * - vid: The ID of the vocabulary the term is assigned to.
+ * - name: The name of the term.
+ * - tid: (optional) The unique ID for the term being saved. If $term->tid is
+ * empty or omitted, a new term will be inserted.
+ * - description: (optional) The term's description.
+ * - format: (optional) The text format for the term's description.
+ * - weight: (optional) The weight of this term in relation to other terms
+ * within the same vocabulary.
+ * - parent: (optional) The parent term(s) for this term. This can be a single
+ * term ID or an array of term IDs. A value of 0 means this term does not
+ * have any parents. When omitting this variable during an update, the
+ * existing hierarchy for the term remains unchanged.
+ * - vocabulary_machine_name: (optional) The machine name of the vocabulary
+ * the term is assigned to. If not given, this value will be set
+ * automatically by loading the vocabulary based on $term->vid.
+ * - original: (optional) The original taxonomy term object before any changes
+ * were applied. When omitted, the unchanged taxonomy term object is
+ * loaded from the database and stored in this property.
+ * Since a taxonomy term is an entity, any fields contained in the term object
+ * are saved alongside the term object.
+ *
* @return
- * Status constant indicating if term was inserted or updated.
+ * Status constant indicating whether term was inserted (SAVED_NEW) or updated
+ * (SAVED_UPDATED). When inserting a new term, $term->tid will contain the
+ * term ID of the newly created term.
*/
function taxonomy_term_save($term) {
// Prevent leading and trailing spaces in term names.
@@ -1092,7 +1115,8 @@ class TaxonomyVocabularyController extends DrupalDefaultEntityController {
* this function.
*
* @return
- * An array of term objects, indexed by tid.
+ * An array of term objects, indexed by tid. When no results are found, an
+ * empty array is returned.
*
* @todo Remove $conditions in Drupal 8.
*/
diff --git a/modules/taxonomy/taxonomy.test b/modules/taxonomy/taxonomy.test
index 1fd47f5ea..97cfe448f 100644
--- a/modules/taxonomy/taxonomy.test
+++ b/modules/taxonomy/taxonomy.test
@@ -350,6 +350,40 @@ class TaxonomyVocabularyUnitTest extends TaxonomyWebTestCase {
// Check that the field instance is still attached to the vocabulary.
$this->assertTrue(field_info_instance('taxonomy_term', 'field_test', $new_name), t('The bundle name was updated correctly.'));
}
+
+ /**
+ * Test uninstall and reinstall of the taxonomy module.
+ */
+ function testUninstallReinstall() {
+ // Fields and field instances attached to taxonomy term bundles should be
+ // removed when the module is uninstalled.
+ $this->field_name = drupal_strtolower($this->randomName() . '_field_name');
+ $this->field = array('field_name' => $this->field_name, 'type' => 'text', 'cardinality' => 4);
+ $this->field = field_create_field($this->field);
+ $this->field_id = $this->field['id'];
+ $this->instance = array(
+ 'field_name' => $this->field_name,
+ 'entity_type' => 'taxonomy_term',
+ 'bundle' => $this->vocabulary->machine_name,
+ 'label' => $this->randomName() . '_label',
+ );
+ field_create_instance($this->instance);
+
+ module_disable(array('taxonomy'));
+ require_once DRUPAL_ROOT . '/includes/install.inc';
+ drupal_uninstall_modules(array('taxonomy'));
+ module_enable(array('taxonomy'));
+
+ // Now create a vocabulary with the same name. All field instances
+ // connected to this vocabulary name should have been removed when the
+ // module was uninstalled. Creating a new field with the same name and
+ // an instance of this field on the same bundle name should be successful.
+ unset($this->vocabulary->vid);
+ taxonomy_vocabulary_save($this->vocabulary);
+ unset($this->field['id']);
+ field_create_field($this->field);
+ field_create_instance($this->instance);
+ }
}
/**