When updating the term hierarchy in admin/structure/taxonomy/ page, it should also invoke the hook_taxonomy_term_update() or any other appropriate hook, therefore, the module can be notified on the hierarchy changes as well.

CommentFileSizeAuthor
#18 core-notify_hierarchy_update-1591404-18.patch601 bytesMiroslavBanov
#13 core-use_taxonomy_term_save-1591404-13.patch1.89 KBAnonymous (not verified)
#10 core-use_taxonomy_term_save-1591404-10.patch1.86 KBAnonymous (not verified)
#9 core-use_taxonomy_term_save-1591404-9.patch1.86 KBAnonymous (not verified)
#8 core-use_taxonomy_term_save-1591404-6.patch1.86 KBAnonymous (not verified)
#6 core-use_taxonomy_term_save-1591404-6.patch1.89 KBAnonymous (not verified)
#3 core-use_taxonomy_term_save-1591404-3.patch1.65 KBAnonymous (not verified)
#2 core-use_taxonomy_term_save-1591404-2.patch1.59 KBAnonymous (not verified)
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Anonymous’s picture

Subscribe

Anonymous’s picture

Category: feature » bug
Status: Active » Needs review
FileSize
1.59 KB

patch is attached. Since the code does not conform to the api, I think this should be a bug report. We should be using taxonomy_term_save() when updating terms, not altering the DB directly.

Anonymous’s picture

Updated patch is attached. Since the code does not conform to the api, I think this should be a bug report. We should be using taxonomy_term_save() when updating terms, not altering the DB directly.

apotek’s picture

This is a good, clean, wholesome move towards leveraging the module's own API, and would enable us module developers to hook into term updates in a much cleaner fashion.

+100 :)

apotek’s picture

Have tested this patch and it works for me.

Anonymous’s picture

Updated patch. Previous patch causes this issue: https://drupal.org/node/2016417

Status: Needs review » Needs work

The last submitted patch, core-use_taxonomy_term_save-1591404-6.patch, failed testing.

Anonymous’s picture

Updating patch that failed testing

Anonymous’s picture

Updating patch that failed testing

Anonymous’s picture

Updating patch that failed testing

Anonymous’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, core-use_taxonomy_term_save-1591404-10.patch, failed testing.

Anonymous’s picture

Status: Needs work » Needs review
FileSize
1.89 KB

Updated patch attached

apotek’s picture

Status: Needs review » Reviewed & tested by the community

This passed three weeks ago. Any reason not to commit?

David_Rothstein’s picture

Status: Reviewed & tested by the community » Needs review

This does definitely seem like the "right" thing to do (and I have had to implement workarounds in the past to get around the fact that this isn't happening), but I think we need to discuss whether we actually should do it in Drupal 7 at this point. There's a possible performance impact on the admin page if tons of terms are going to be saved at once, plus the sudden triggering of hooks on each one of these which didn't happen before could have unexpected effects depending on what those hook implementations are doing. As an extreme example, I have worked on sites that use https://drupal.org/project/deploy to deploy changes to taxonomy terms between sites on save, and it would be unexpected to suddenly deal with 50 or so of those on a single page request.

Also, #1818560: Convert taxonomy entities to the new Entity Field API did this for Drupal 8 (as part of a larger set of changes) and didn't wind up with a @todo, so I'm curious why the implementation in this issue came out so different...

There are some minor code style issues in the patch too, such as:

+    } else {
+      // TODO: Handle multiple parents after UI bug is fixed

"else {" should be on its own line, and use @todo - see https://drupal.org/coding-standards

Anonymous’s picture

The taxonomy term page already has performance issues. I can't list a vocabulary's terms when the list tops 3000.

Making this change would deliver a complete set of terms modified. Other modules expect the appropriate hooks to be triggered when terms are modified. Changing a term's hierarchy should be captured as a change to a term.

apotek’s picture

@David_Rothstein I appreciate your really thoughtful response. It would be interesting if someone could test this patch with deploy or migrate module (any kind of bulk movement of terms). But in the end, this really is the right thing to do. You can't really argue with @SpaJenniOs here.

Changing a term's hierarchy should be captured as a change to a term.

And a change to a term should trigger some kind of hook/event that can tapped in to.

Now, where we might find some operable middle ground is that maybe a change to a term's hierarchy doesn't necessarily have to trigger a taxonomy_term_save(). Perhaps what should happen is that we create a new hook for the taxonomy module. taxonomy_term_update_hierarchy(). That function could do a module_invoke_all.

Doing it this way would have two benefits:

1. Reduce the impact on existing code since no modules have implemented this new hook yet.
2. Still allow modules to hook into the change to the hierarchy and respond in an appropriately drupally fashion.

The drawback is that we loose the centrality of taxonomy_term_save(), which is, as @SpaJenniOS points out, the "real" place where term changes should be channeled and worked with.

MiroslavBanov’s picture

Here is the other approach - to invoke a different hook so other modules can react to the hierarchy change.