Customize workflow emails

Permalink
I would like to customize the email content that gets sent when certain workflow actions happen. For example, the email that gets sent when a new calendar event gets submitted and is pending approval. Does anyone know how to modify the content of these emails? I figured out how to make a few modifications if I change the code in the core file concrete\src\Workflow\Request\ApproveCalendarEventRequest.php, but obviously I don't want to go that route. I also tried extending the core file using the example fromhttps://documentation.concrete5.org/developers/framework/extending-c... but I couldn't get that working either. Maybe it is because the ApproveCalendarEventRequest isn't extendable?

derekairdrie
 
mnakalay replied on at Permalink Reply
mnakalay
Hello,

most emails sent by concrete use email templates located in concrete/emails

If you copy any of those templates and put the copy in application/mails (keeping the same file name) concrete will start using the copy. So you can modify it to your liking.

I am not sure that's exactly what you had in mind so feel free to provide more information if you need a different solution.
derekairdrie replied on at Permalink Reply
derekairdrie
Thank you for the reply. Although I can use that method to modify the static content for all workflow emails, it doesn't quite give me what I'm after. The workflow emails contain dynamic content, and I'd like to expand on that to include additional details about the event. So for example to display the calendar event description in the email, rather than just the title.
Copying the "basic_workflow_notification.php" file into application/mail and making changes to it really only allows the static content in the email to be modified and that content would be the same for any email triggered from workflow.
mnakalay replied on at Permalink Best Answer Reply
mnakalay
unfortunately you can't override the class ApproveCalendarEventRequest because every time it is instantiated it's with new ApproveCalendarEventRequest() instead of with the Laravel container.

You should look at another way.

You might be able, using laravel's bind() function to override Concrete\Core\Workflow\BasicWorkflow with your own class.

It seems that class is instantiated using Laravel's container so it should work.

That class contains the notify() method that sends the email and from there you can add parameters to the email and modify the message and other elements you send to the email template.
derekairdrie replied on at Permalink Reply
derekairdrie
Awesome thank you for the information. I will see if I can get the Laravel bind() method working.
derekairdrie replied on at Permalink Reply
derekairdrie
Thank you so much. I was able to get bind() to work for what I needed. I ended up putting this code in app.php:

$app->bind('\Concrete\Core\Workflow\BasicWorkflow', function($app, $params) {
    return new \Application\BasicWorkflow($params[0]);
});


And then overrode the notify() function in my custom class to check if the notification was for a calendar event, and then retrieved the event details as follows:

if ($wp->wpCategoryHandle == 'calendar_event'){            
    $event = $wp->getWorkflowRequestObject()->getRequestedEventVersionObject();
}


From there is was just a matter of modifying the message by overriding the getTranslatedMessage() function to embed the details of the calendar event.

Thanks again
mnakalay replied on at Permalink Reply
mnakalay
This is great! Thank you for sharing :)