Skip to content

Commit 2e266c9

Browse files
committed
MessageAdmin - support sending yourself a test email with Outbound Message extension
1 parent 1b4f207 commit 2e266c9

3 files changed

Lines changed: 28 additions & 0 deletions

File tree

ext/message_admin/CRM/MessageAdmin/Settings.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,17 @@ public static function getAll() {
1616
->execute()
1717
->single()['params']['language']['options'];
1818

19+
$outboundMessageEnabled = (bool) \Civi\Api4\Extension::get(FALSE)
20+
->addWhere('key', '=', 'outbound_message')
21+
// note: status = installed actually means enabled :/
22+
->addWhere('status:name', '=', 'installed')
23+
->execute()
24+
->first();
25+
1926
return [
2027
'allLanguages' => CRM_Utils_Array::subset($allLangsIdx, $usableLangs),
2128
'uiLanguages' => CRM_Core_I18n::uiLanguages(),
29+
'sendTestEnabled' => $outboundMessageEnabled,
2230
];
2331
}
2432

ext/message_admin/ang/crmMsgadm/Preview.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
</div>
1414
<div class="navbar-form navbar-right">
1515
<div class="form-group">
16+
<button class="crm-button" ng-click="$ctrl.sendTest.send()" ng-if="!$ctrl.loading && $ctrl.sendTest">
17+
<i class="crm-i fa-paper-plane" role="img" aria-disabled="true"></i>
18+
{{:: ts('Send test') }}
19+
</button>
1620
<button crm-icon="fa-times" type="button" class="btn btn-default" ng-click="previewMsgDlg.close()">
1721
{{::ts('Close')}}
1822
</button>

ext/message_admin/ang/crmMsgadm/Preview.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,22 @@
110110
$scope.$watch('$ctrl.formatId', update);
111111
$scope.$watch('$ctrl.exampleId', update);
112112
update();
113+
114+
this.sendTest = CRM.crmMsgadm.sendTestEnabled ? {
115+
send: () => {
116+
const subject = this.preview.subject;
117+
const body = this.preview.html;
118+
return crmStatus({start: ts('Sending...'), success: ts('Sent')}, crmApi4('EmailMessage', 'create', {
119+
values: {
120+
// TODO: enable selecting other contacts to receive test?
121+
to_contact_id: 'user_contact_id',
122+
subject: subject,
123+
body: body,
124+
}
125+
}));
126+
}
127+
} : null;
128+
113129
});
114130

115131
})(angular, CRM.$, CRM._);

0 commit comments

Comments
 (0)