While investigating why an operation was being triggered by content moderators when they published comments but not when they unpublished comments, I found that hook_comment_unpublish() is documented but does not actually exist.

I grepped through the Drupal 7/8 codebase for module_invoke_all('comment_unpublish' and didn't find any results and the documentation page doesn't list any invocations.

Marking this as major since Forum, Search and Tracker implement this hook in D7 while Forum, Node and Tracker implement this in D8 but feel free to change the status. Tracker and Forum both include their own workarounds for this issue which can be removed.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Devin Carlson’s picture

A patch to invoke hook_comment_unpublish() with a test to demonstrate the issue. It also removes the workarounds that are currently in place.

The last submitted patch, 1: comment-unpublish-d8-2289369-1.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 1: comment-unpublish-d8-2289369-1-tests-only.patch, failed testing.

mcjim’s picture

Well spotted. Looks like this was never implemented in Drupal 7.

Just one thing: shouldn't we have tests in forum and tracker rather than CommentPublishTest? Not sure that's actually testing that the hooks are invoked as such, unless it's Friday afternoon and my brain's turned to mush, which is a distinct possibility.

larowlan’s picture

I vote we remove it in favor of the more general update hook. No other entity has a published hook

g3r4’s picture

Status: Needs work » Needs review
FileSize
3.66 KB

I've worked on a candidate patch for the removal of the content_unpublished hook since it's not being used

larowlan’s picture

jhodgdon’s picture

I'm closing that other issue as a duplicate, although is this issue covering the fact that hook_comment_publish() is being invoked on every save if the status is published (which is not how it's documented)?

jhodgdon’s picture

I guess given the patch here, this issue is not covering the publish hook. So I reopened the other one to deal with that. Or we can close this one as a duplicate.

jhodgdon’s picture

Status: Needs review » Closed (duplicate)

Sorry for being so indecisive. I think we should go ahead and close this issue as a duplicate of the other one, since the other one is more comprehensive.