Commit ddaba8bf authored by alexpott's avatar alexpott
Browse files

Issue #2294375 by jhodgdon: Fixed Comment publish/unpublish hooks are not invoked correctly.

parent 3181fddb
......@@ -144,26 +144,6 @@ function hook_comment_view_alter(array &$build, \Drupal\comment\Entity\Comment $
$build['#post_render'][] = 'my_module_comment_post_render';
}
/**
* Respond to a comment being published by a moderator.
*
* @param \Drupal\comment\Comment $comment
* The comment the action is being performed on.
*/
function hook_comment_publish(Drupal\comment\Comment $comment) {
drupal_set_message(t('Comment: @subject has been published', array('@subject' => $comment->getSubject())));
}
/**
* Respond to a comment being unpublished by a moderator.
*
* @param \Drupal\comment\Comment $comment
* The comment the action is being performed on.
*/
function hook_comment_unpublish(Drupal\comment\Comment $comment) {
drupal_set_message(t('Comment: @subject has been unpublished', array('@subject' => $comment->getSubject())));
}
/**
* Act before comment deletion.
*
......
......@@ -146,9 +146,6 @@ public function postSave(EntityStorageInterface $storage, $update = TRUE) {
$this->releaseThreadLock();
// Update the {comment_entity_statistics} table prior to executing the hook.
$storage->updateEntityStatistics($this);
if ($this->isPublished()) {
\Drupal::moduleHandler()->invokeAll('comment_publish', array($this));
}
}
/**
......
......@@ -357,36 +357,19 @@ function forum_permission() {
return $perms;
}
/**
* Implements hook_comment_publish().
*
* This actually handles the insertion and update of published nodes since
* $comment->save() calls hook_comment_publish() for all published comments.
*/
function forum_comment_publish(CommentInterface $comment) {
if ($comment->getCommentedEntityTypeId() == 'node') {
\Drupal::service('forum.index_storage')->updateIndex($comment->getCommentedEntity());
}
}
/**
* Implements hook_comment_update().
*
* The Comment module doesn't call hook_comment_unpublish() when saving
* individual comments, so we need to check for those here.
*/
function forum_comment_update(CommentInterface $comment) {
// $comment->save() calls hook_comment_publish() for all published comments,
// so we need to handle all other values here.
if (!$comment->isPublished() && $comment->getCommentedEntityTypeId() == 'node') {
if ($comment->getCommentedEntityTypeId() == 'node') {
\Drupal::service('forum.index_storage')->updateIndex($comment->getCommentedEntity());
}
}
/**
* Implements hook_comment_unpublish().
* Implements hook_comment_insert().
*/
function forum_comment_unpublish(CommentInterface $comment) {
function forum_comment_insert(CommentInterface $comment) {
if ($comment->getCommentedEntityTypeId() == 'node') {
\Drupal::service('forum.index_storage')->updateIndex($comment->getCommentedEntity());
}
......
......@@ -1673,23 +1673,3 @@ function node_comment_delete($comment) {
node_reindex_node_search($comment->getCommentedEntityId());
}
}
/**
* Implements hook_comment_publish().
*/
function node_comment_publish($comment) {
// Reindex the node when comments are published.
if ($comment->getCommentedEntityTypeId() == 'node') {
node_reindex_node_search($comment->getCommentedEntityId());
}
}
/**
* Implements hook_comment_unpublish().
*/
function node_comment_unpublish($comment) {
// Reindex the node when comments are unpublished.
if ($comment->getCommentedEntityTypeId() == 'node') {
node_reindex_node_search($comment->getCommentedEntityId());
}
}
......@@ -186,36 +186,24 @@ function tracker_node_predelete(EntityInterface $node, $arg = 0) {
/**
* Implements hook_comment_update().
*
* Comment module doesn't call hook_comment_unpublish() when saving individual
* comments so we need to check for those here.
*/
function tracker_comment_update(CommentInterface $comment) {
// $comment->save() calls hook_comment_publish() for all published comments
// so we need to handle all other values here.
if (!$comment->isPublished() && $comment->getCommentedEntityTypeId() == 'node') {
_tracker_remove($comment->getCommentedEntityId(), $comment->getOwnerId(), $comment->getChangedTime());
}
}
/**
* Implements hook_comment_publish().
*
* This actually handles the insert and update of published nodes since
* $comment->save() calls hook_comment_publish() for all published comments.
*/
function tracker_comment_publish(CommentInterface $comment) {
if ($comment->getCommentedEntityTypeId() == 'node') {
_tracker_add($comment->getCommentedEntityId(), $comment->getOwnerId(), $comment->getChangedTime());
if ($comment->isPublished()) {
_tracker_add($comment->getCommentedEntityId(), $comment->getOwnerId(), $comment->getChangedTime());
}
else {
_tracker_remove($comment->getCommentedEntityId(), $comment->getOwnerId(), $comment->getChangedTime());
}
}
}
/**
* Implements hook_comment_unpublish().
* Implements hook_comment_insert().
*/
function tracker_comment_unpublish(CommentInterface $comment) {
if ($comment->getCommentedEntityTypeId() == 'node') {
_tracker_remove($comment->getCommentedEntityId(), $comment->getOwnerId(), $comment->getChangedTime());
function tracker_comment_insert(CommentInterface $comment) {
if ($comment->getCommentedEntityTypeId() == 'node' && $comment->isPublished()) {
_tracker_add($comment->getCommentedEntityId(), $comment->getOwnerId(), $comment->getChangedTime());
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment