Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

autogenerate the plain text version after token substitution #20

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/Listener/DefaultComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
*/
class DefaultComposer extends BaseListener {

protected $autoGeneratePlainText = FALSE;

public function onRun(RunEvent $e) {
// FIXME: This probably doesn't belong here...
if (defined('CIVICRM_MAIL_SMARTY') && CIVICRM_MAIL_SMARTY) {
Expand Down Expand Up @@ -78,6 +80,9 @@ public function onCompose(ComposeBatchEvent $e) {
'text/plain');
$tp->addMessage('body_html', isset($tpls['html']) ? $tpls['html'] : '',
'text/html');
if (empty($tpls['text'])) {
$this->autoGeneratePlainText = TRUE;
}

$hasContent = FALSE;
foreach ($e->getTasks() as $key => $task) {
Expand Down Expand Up @@ -160,10 +165,14 @@ public function createMailParams(
FlexMailerTask $task,
TokenRow $row
) {
$html = $row->render('body_html');
$text = $this->autoGeneratePlainText ?
\CRM_Utils_String::htmlToText($html) :
$row->render('body_text');
return array(
'Subject' => $row->render('subject'),
'text' => $row->render('body_text'),
'html' => $row->render('body_html'),
'text' => $text,
'html' => $html,
);
}

Expand Down