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.
My setup is the following:
- A taxonomy 'expertises' with some terms
- A few hundred users with a term_reference field to their expertise
- An overview using Search API SOLR and FacetAPI to filter users on their expertise
All works fine. However, when I delete a term, Search API doesn't see that it needs to re-index the user entities. The filter remains visible (although now by showing the term ID instead of its label), until I totally clear the index and re-index.
Am I doing something wrong or is this a bug?
Comments
Comment #1
drunken monkeyIt is a bug, but I'd rather say it's one in Drupal core. When a taxonomy term is deleted, I'd say that term reference fields should be updated accordingly and the entity update hook of the parent entity called. This doesn't seem to be the case at the moment, however.
A correct handling of this case in Drupal core would solve your problem, as Search API observes these general hooks, instead of trying to find out the implications of specific actions (like deleting terms).
Comment #2
BarisW CreditAttribution: BarisW commentedHmm, I thought Drupal core already handles this using hook_taxonomy_term_delete?
When a term is deleted, the entry in the table 'taxonomy_index' is deleted as well.
However, the search index doesn't gets updated. Even if this is core bug, what would be the way for me to do this in my own module?
Comment #3
drunken monkeyYou could implement
hook_taxonomy_term_delete()
(preferably in a way such that it executes beforetaxonomy_taxonomy_term_delete()
) and manually delete references to that term from all nodes which include one (you can use thetaxonomy_index
table for that, if your hook implementation is called beforetaxonomy_taxonomy_term_delete()
). This should also triggerhook_entity_update()
for those nodes, fixing this problem.Another way would be to use Rules to mark nodes as "dirty" (i.e., needing indexing) when taxonomy terms they reference are deleted. Don't know how well that would work, though.
Comment #4
David_Rothstein CreditAttribution: David_Rothstein commented#1281114: Database records not deleted for Term Reference Fields after Term is Deleted