Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Try Vanilla Forums Cloud product
After February 6, this site will no longer have Facebook, Twitter, or OpenID sign-in options. Read our announcement about social media SSO support in 2.8 for more info.

Make sure you have a current, valid email address set in your profile and set a password so you can login without it. If you get locked out after that time, you can choose "Forgot Password" to fix it as long as a valid email is on your account.

How to Disable Commenting on Custom Activity Types?

ShadowdareShadowdare π Moderator
edited May 2015 in Development

I would like to disable commenting on Article and ArticleComment activity types.

I have defined those activity types in the Article app's structure.php file with:

$ActivityModel = new ActivityModel();
$ActivityModel->DefineType('Article');
$ActivityModel->DefineType('ArticleComment');

This creates two new rows in the GDN_ActivityType table with the AllowComments field set to the default of 0 (false).

When I insert a new activity with either the Article or the ArticleComment activity type, I can still leave a comment on the activities when comments shouldn't be allowed. It's the same on both an admin account and a normal user account.

I see that the comments link for activities doesn't have any logic to hide the link if AllowComments is set to false. Reference: https://github.com/vanilla/vanilla/blob/master/applications/dashboard/views/activity/helper_functions.php#L82

Is the AllowComments property being ignored and simply not used in the code, or is there another way to do this?

Add Pages to Vanilla with the Basic Pages app | Publish articles with the Articles app

R_Jhgtonight

Comments

  • LincLinc Director of Development Detroit Vanilla Staff

    Wow, yeah, looks like AllowComments is a dummy db field that either didn't get implemented or got supplanted by a calculated value. I don't have a good suggestion on this one.

    Shadowdare
  • hgtonighthgtonight ∞ · New Moderator

    Huh, I didn't even think about this when I was creating new activity types. Good find @Shadowdare.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • businessdadbusinessdad Stealth contributor MVP

    Possible trick: implement a handler for ActivityController_AfterActivityBody. In it, set the following:

    // Keep $ID empty (line 75)
    $Sender->EventArguments['Activity']->SharedNotifyUserID = null;
    // Keep $ID empty (line 77)
    $Sender->EventArguments['Activity']->CommentNotifyUserID = null;
    // At this point $SharedString should be empty as well. Set $Activity->NotifyUserID to 
    // any value greater than zero
    $Sender->EventArguments['Activity']->NotifyUserID = 12345;
    
    // Now $AllowComments = $Activity->NotifyUserID < 0 || $SharedString; should 
    // always return false, disabling comments
    
    Shadowdare
Sign In or Register to comment.