Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
ddaba8bf
Commit
ddaba8bf
authored
Jul 07, 2014
by
Alex Pott
Browse files
Issue
#2294375
by jhodgdon: Fixed Comment publish/unpublish hooks are not invoked correctly.
parent
3181fddb
Changes
5
Hide whitespace changes
Inline
Side-by-side
core/modules/comment/comment.api.php
View file @
ddaba8bf
...
...
@@ -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.
*
...
...
core/modules/comment/src/Entity/Comment.php
View file @
ddaba8bf
...
...
@@ -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
));
}
}
/**
...
...
core/modules/forum/forum.module
View file @
ddaba8bf
...
...
@@ -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
());
}
...
...
core/modules/node/node.module
View file @
ddaba8bf
...
...
@@ -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
());
}
}
core/modules/tracker/tracker.module
View file @
ddaba8bf
...
...
@@ -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
());
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment