Jump to content

Comments module outgoing message customization


encho
 Share

Recommended Posts

I would like to know if there's a way to customize the outgoing message (sent to moderator/administrator of comments) when comment is posted? I would like that message to:

1. Have different subject

2. Contain the link to easily approve the comment (one-click), or at least bring you to page/edit where you can edit the page in question..

Not sure if possible at all, but all inputs appreciated. Also, I would like someone to give me working example of using "requireSecurityField" option when rendering the comment form (as I am not javascript guru). Thanks all!
 

Link to comment
Share on other sites

I would like to know if there's a way to customize the outgoing message (sent to moderator/administrator of comments) when comment is posted? I would like that message to:

1. Have different subject

2. Contain the link to easily approve the comment (one-click), or at least bring you to page/edit where you can edit the page in question..

Not sure if possible at all, but all inputs appreciated. Also, I would like someone to give me working example of using "requireSecurityField" option when rendering the comment form (as I am not javascript guru). Thanks all!

Hi, i looked to module code and seems like dont support own email format now. Mail localization will be supported.

About SecurityFiled:

Form render in template must have 'requireSecurityField' => 'security_field'

$outSendForm = $page->comments->renderForm(array('requireSecurityField' => 'security_field'));

And needed javascript is here:

<script type="text/javascript" charset="utf-8">
  $(document).ready(function(){
    var $input = "<input type='hidden' name='security_field' value='1' />";
    $("#CommentForm form").append($input);
    $("#CommentForm").show();
  });
</script>

Comments documentation.

  • Like 2
Link to comment
Share on other sites

  • 1 month later...

One way you could do it would be to make the FieldtypeComments::sendNotificationEmail method hookable. If you want to add 3 underscores before that function name (in /wire/modules/Fieldtype/FieldtypeComments.module), I'll make the same change here. From there, it should be hookable. In this case, you'd probably want to override/replace the method completely. To do this, your hook function would populate the $event->replace=true; Using PW 2.3 dev syntax: 

wire()->addHookBefore('FieldtypeComments::sendNotificationEmail', function(HookEvent $event) {
  $event->replace = true; 
  $page = $event->arguments(1);
  $field = $event->arguments(2);
  $comment = $event->arguments(3); 
  $subject = "New Comment Posted!";
  $body = "A new comment was posted to $page->httpUrl by $comment->cite: $comment->text";
  mail($field->notificationEmail, $subject, $body); 
}); 
  • Like 2
Link to comment
Share on other sites

Hi Ryan,

This seems great! I'll give it a test tomorrow.

For the project I'm working on I needed to mimicking some functionality from Basecamp where users can select people to notify of a new comment via checkboxes. In this case it's a list of 5-8 people who have a particular role.

In order to make it work, I needed multiple custom messages based on $page->template — while leaving the default message in place for existing pages with comments. I also needed an additional field to store the list of email address that need notified of the comment.

I happened across this thread and decided to give it a shot. It was pretty easy to add the additional field to the DB and update the module in a few places. I now have an additional field ($comment->notifications) that is output as a hidden field and populated with email addresses via JS. The security concerns are low since all users are trusted and authenticated. ;)

The whole thing is pretty specific to the needs of this project, but (as always) I was shocked at how easy it was to get working.

:)

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...