diff options
author | webchick <webchick@24967.no-reply.drupal.org> | 2012-03-01 20:23:24 -0800 |
---|---|---|
committer | webchick <webchick@24967.no-reply.drupal.org> | 2012-03-01 20:23:24 -0800 |
commit | 824eb3cd6cb0ab7bd01531c7a1971b2d77ed8886 (patch) | |
tree | 9b2d846817c9c3b550ceca627635475b9be8881b /modules/taxonomy/taxonomy.module | |
parent | 6d051a1f0183f5d6f2fd2e0141de0ae0adebfc80 (diff) | |
download | brdo-824eb3cd6cb0ab7bd01531c7a1971b2d77ed8886.tar.gz brdo-824eb3cd6cb0ab7bd01531c7a1971b2d77ed8886.tar.bz2 |
Issue #687180 by Island Usurper, catch, Berdir, Damien Tournoud, xjm, anthbel: Fixed Deleting a taxonomy vocabulary leaves term reference fields still pointing to it, and a PDO Exception when creating content.
Diffstat (limited to 'modules/taxonomy/taxonomy.module')
-rw-r--r-- | modules/taxonomy/taxonomy.module | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module index 28d488ec8..3879efdb6 100644 --- a/modules/taxonomy/taxonomy.module +++ b/modules/taxonomy/taxonomy.module @@ -475,6 +475,30 @@ function taxonomy_vocabulary_delete($vid) { module_invoke_all('taxonomy_vocabulary_delete', $vocabulary); module_invoke_all('entity_delete', $vocabulary, 'taxonomy_vocabulary'); + // Load all Taxonomy module fields and delete those which use only this + // vocabulary. + $taxonomy_fields = field_read_fields(array('module' => 'taxonomy')); + foreach ($taxonomy_fields as $field_name => $taxonomy_field) { + $modified_field = FALSE; + // Term reference fields may reference terms from more than one + // vocabulary. + foreach ($taxonomy_field['settings']['allowed_values'] as $key => $allowed_value) { + if ($allowed_value['vocabulary'] == $vocabulary->machine_name) { + unset($taxonomy_field['settings']['allowed_values'][$key]); + $modified_field = TRUE; + } + } + if ($modified_field) { + if (empty($taxonomy_field['settings']['allowed_values'])) { + field_delete_field($field_name); + } + else { + // Update the field definition with the new allowed values. + field_update_field($taxonomy_field); + } + } + } + cache_clear_all(); taxonomy_vocabulary_static_reset(); |