Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The function that I found triggering the hook_taxonomy_vocabulary_delete
function taxonomy_vocabulary_delete($vid) {
$vocabulary = (array) taxonomy_vocabulary_load($vid);
// Only load terms without a parent, child terms will get deleted too.
$result = db_query('SELECT t.tid FROM {taxonomy_term_data} t INNER JOIN {taxonomy_term_hierarchy} th ON th.tid = t.tid WHERE t.vid = :vid AND th.parent = 0', array(':vid' => $vid))->fetchCol();
foreach ($result as $tid) {
taxonomy_term_delete($tid);
}
db_delete('taxonomy_vocabulary')
->condition('vid', $vid)
->execute();
field_attach_delete_bundle('taxonomy_term', $vocabulary['machine_name']);
module_invoke_all('taxonomy_vocabulary_delete', $vocabulary);
module_invoke_all('entity_delete', $vocabulary, 'taxonomy_vocabulary');
cache_clear_all();
entity_get_controller('taxonomy_vocabulary')->resetCache();
return SAVED_DELETED;
}
The documentation for the hook:
/**
* Respond to the deletion of taxonomy vocabularies.
*
* Modules implementing this hook can respond to the deletion of taxonomy
* vocabularies from the database.
*
* @param $vocabulary
* A taxonomy vocabulary object.
*/
function hook_taxonomy_vocabulary_delete($vocabulary) {
if (variable_get('taxonomy_' . $vocabulary->vid . '_synonyms', FALSE)) {
variable_del('taxonomy_' . $vocabulary->vid . '_synonyms');
}
}
In the actual code, the $vocabolary
is cast to array, but in the documentation, the $vocabolary
is used as an object.
I've attached a patch with the needed documentation fixes.
Comment | File | Size | Author |
---|---|---|---|
#3 | taxonomy_vocab_delete-965348.patch | 1.11 KB | yched |
hook_taxonomy_vocabulary_delete-documentation-update.patch | 753 bytes | googletorp | |
Comments
Comment #1
yched CreditAttribution: yched commentedPassing a vocab as an array sounds weird.
hook_entity_delete() also expects an object, so this is most probably an overlook when the hooks invocations were added.
Comment #2
yched CreditAttribution: yched commentedIndeed, those two hook invocations were added in #709892: Complete entity CRUD hook invocations. Posted a note over there, for now marking as duplicate.
Comment #3
yched CreditAttribution: yched commentedActually, I have no clue why we have this array cast.
Let's try simply removing it - and the issue is probably best handled in this thread.
Comment #4
yched CreditAttribution: yched commentedchange title accordingly
Comment #5
sunFor reference: http://api.drupal.org/api/drupal/modules--taxonomy--taxonomy.module/func...
Comment #6
catchArray cast makes no sense to me either. It's likely it's just been there for a long time and not removed until now. Confirming rtbc.
Comment #7
webchickYeah, it looks like every other hook_taxonomy_foo() function takes the term/vocab as an object, so this is weird here. According to testbot this doesn't break anything.
Committed to HEAD.