Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi,
So I'm building a website that allows all authenticated users to post comments without approval. However for various reasons I need to allow comments to be unpublished. Unfortunately there's a line of code in Comment Access's implementation of hook_comment_presave() that is forcing the comments to be published.
function commentaccess_comment_presave($comment) {
// Check if the comment needs approval.
...
else {
// No approval necessary: post comment directly!
$comment->status = COMMENT_PUBLISHED;
}
}
My solution for now was simply to comment out the line of code for now as that met my requirements.
Comment | File | Size | Author |
---|---|---|---|
#1 | stop-forced-publish-on-pre-save-195338-01.patch | 593 bytes | Dave Bagler |
Comments
Comment #1
Dave Bagler CreditAttribution: Dave Bagler commentedI've attached a very small patch (just comments out the one line and explains why).
Comment #2
Dave Bagler CreditAttribution: Dave Bagler commentedComment #3
Alan D. CreditAttribution: Alan D. commentedFalling back to core permissions is better maybe?
$status = (user_access('skip comment approval') ? COMMENT_PUBLISHED : COMMENT_NOT_PUBLISHED);
So better to do nothing here? It should already be set
Comment #4
Dave Bagler CreditAttribution: Dave Bagler commentedI ended up coding a smaller custom solution that just met my specific requirements rather than the more broad requirements of the comment access module. @Alan D. You're probably right, core permissions might be a better solution to this issue.
Comment #5
loze CreditAttribution: loze commentedI ran into this bug with a custom module that should of been publishing/unpublishing comments. Took me forever to figure out what was interfering.
I think this commentaccess should simple check if the comment object has a cid and bail if it does. We only need it acting on new comments not when editing existing comments.
I propose putting the following at the beginning of commentaccess_comment_presave():
if(!empty($comment->cid)){
return;
}