Hello,

Submit handler for adding or removing a parent for a term will load the term, based on $form_state values, run a query to update hierarchy table and after that it calls taxonomy_term_save($term), using the non-updated $term object.

That means we'll not have the new parents ids in the taxonomy_term_presave hook and for remove handler, the parents can't be removed, because even if db_delete will update the table, the taxonomy_term_save function will put parents back.

The key part is to replace the db_insert()/db_delete() part with populating the $term object with new parents ids.

CommentFileSizeAuthor
#1 parents_update-1972256-1.patch2.74 KBCracu
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Cracu’s picture

Issue summary: View changes

updated message

Cracu’s picture

Issue summary: View changes

update message.

Cracu’s picture

I propose the attached patch.

Cracu’s picture

Title: Updated parents tids of a term from UI cannot be used in hook_taxonomy_term_presave(). » Updating parents issues (adding/removing).
Category: feature » bug
Cracu’s picture

Issue summary: View changes

noticed also a bug.

Cracu’s picture

Issue summary: View changes

Updated message

Cracu’s picture

Status: Active » Needs review

Updating status to review the patch.

mfernea’s picture

Status: Needs review » Reviewed & tested by the community

I confirm that the patch at #1 works.

mh86’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for the patch and review!

Committed #1.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Update message.