Question

I'm trying to build a simple ticketing system with Drupal 8.6. I'm able to create a content type for these tickets and the comments will be the responses to the ticket. Also I have a status field for open, pending, and closed. I want to be able to email all the users on the ticket if the node is updated or commented on. And I have another user reference field for "assigned ticket to".

What modules would I need that work with 8.6 to get this kind of funtionality? I prefer no modules, but I'm not sure if core itself supports this type of thing.

Was it helpful?

Solution

I recently did something similar, for reacting when the node is updated i used hook_node_presave(). Here's an example on how to send an email when the node is updated and the status is changed from "open" to "pending".

function my_module_node_presave(NodeInterface $node){
  if($node->getType() == 'your_content_type_name' AND $node->isNew() == FALSE) {
   $status_original = $node->original->get('status_field')->value;
   $status_updated = $node->get('status_field')->value;

 if ($status_original !== $status_updated AND $status_original == 'open' AND $status_updated == 'pending') {
   send_mail();
  }
 }
}

For creating the send_mail function or whatever you'd like to call it i used the following resource and modified the code where necessary: How to send a mail programmatically in Drupal 8. Also, i used the SMTP Authentication Support module to send the emails using a gmail account: SMTP Authentication Support. The configuration page of the module is on admin/config/system/smtp.

For checking if a comment has been posted you can use hook_ENTITY_TYPE_insert() and replace "ENTITY_TYPE" with "comment" and inside the hook you can call again the send_mail function.

I did not quite understood how you are storing "all the users on the ticket", but it would be the case of getting the users email address with getEmail();

Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top