3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * This api exposes CiviCRM message_template.
15 * @package CiviCRM_APIv3
19 * Create message template.
21 * @param array $params
24 * @throws \API_Exception
26 function civicrm_api3_message_template_create($params) {
27 return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__
), $params, 'MessageTemplate');
31 * Adjust Metadata for Create action.
33 * The metadata is used for setting defaults, documentation & validation.
35 * @param array $params
36 * Array of parameters determined by getfields.
38 function _civicrm_api3_message_template_create_spec(&$params) {
39 $params['msg_title']['api.required'] = 1;
40 $params['is_active']['api.default'] = TRUE;
41 /* $params['entity_id']['api.required'] = 1;
42 $params['entity_table']['api.default'] = "civicrm_contribution_recur";
43 $params['type']['api.default'] = "R";
48 * Delete message template.
50 * @param array $params
55 function civicrm_api3_message_template_delete($params) {
56 return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__
), $params);
60 * Adjust metadata for message_template get action.
62 * @param array $params
64 function _civicrm_api3_message_template_get_spec(&$params) {
65 // fetch active records by default
66 $params['is_active']['api.default'] = 1;
70 * Retrieve one or more message_template.
72 * @param array $params
73 * Array of name/value pairs.
78 function civicrm_api3_message_template_get($params) {
79 return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__
), $params);
85 * @param array $params
86 * @throws API_Exception
88 function civicrm_api3_message_template_send($params) {
89 // Change external param names to internal ones
91 _civicrm_api3_message_template_send_spec($fieldSpec);
93 foreach ($fieldSpec as $field => $spec) {
94 if (isset($spec['api.aliases']) && array_key_exists($field, $params)) {
95 $params[CRM_Utils_Array
::first($spec['api.aliases'])] = $params[$field];
96 unset($params[$field]);
99 if (empty($params['messageTemplateID'])) {
100 if (empty($params['groupName']) ||
empty($params['valueName'])) {
101 // Can't use civicrm_api3_verify_mandatory for this because it would give the wrong field names
102 throw new API_Exception(
103 "Mandatory key(s) missing from params array: requires id or option_group_name + option_value_name",
105 ["fields" => ['id', 'option_group_name', 'option_value_name']]
109 CRM_Core_BAO_MessageTemplate
::sendTemplate($params);
113 * Adjust Metadata for Create action.
115 * The metadata is used for setting defaults, documentation &
118 * @param array $params
119 * Array of parameters determined by getfields.
121 function _civicrm_api3_message_template_send_spec(&$params) {
122 $params['id']['description'] = 'ID of the template';
123 $params['id']['title'] = 'Message Template ID';
124 $params['id']['api.aliases'] = ['messageTemplateID', 'message_template_id'];
125 $params['id']['type'] = CRM_Utils_Type
::T_INT
;
127 $params['option_group_name']['description'] = 'option group name of the template (required if no id supplied)';
128 $params['option_group_name']['title'] = 'Option Group Name';
129 $params['option_group_name']['api.aliases'] = ['groupName'];
130 $params['option_group_name']['type'] = CRM_Utils_Type
::T_STRING
;
132 $params['option_value_name']['description'] = 'option value name of the template (required if no id supplied)';
133 $params['option_value_name']['title'] = 'Option Value Name';
134 $params['option_value_name']['api.aliases'] = ['valueName'];
135 $params['option_value_name']['type'] = CRM_Utils_Type
::T_STRING
;
137 $params['contact_id']['description'] = 'contact id if contact tokens are to be replaced';
138 $params['contact_id']['title'] = 'Contact ID';
139 $params['contact_id']['api.aliases'] = ['contactId'];
140 $params['contact_id']['type'] = CRM_Utils_Type
::T_INT
;
142 $params['template_params']['description'] = 'additional template params (other than the ones already set in the template singleton)';
143 $params['template_params']['title'] = 'Template Params';
144 $params['template_params']['api.aliases'] = ['tplParams'];
147 $params['from']['description'] = 'the From: header';
148 $params['from']['title'] = 'From';
149 $params['from']['type'] = CRM_Utils_Type
::T_STRING
;
151 $params['to_name']['description'] = 'the recipient’s name';
152 $params['to_name']['title'] = 'Recipient Name';
153 $params['to_name']['api.aliases'] = ['toName'];
154 $params['to_name']['type'] = CRM_Utils_Type
::T_STRING
;
156 $params['to_email']['description'] = 'the recipient’s email - mail is sent only if set';
157 $params['to_email']['title'] = 'Recipient Email';
158 $params['to_email']['api.aliases'] = ['toEmail'];
159 $params['to_email']['type'] = CRM_Utils_Type
::T_STRING
;
161 $params['cc']['description'] = 'the Cc: header';
162 $params['cc']['title'] = 'CC';
163 $params['cc']['type'] = CRM_Utils_Type
::T_STRING
;
165 $params['bcc']['description'] = 'the Bcc: header';
166 $params['bcc']['title'] = 'BCC';
167 $params['bcc']['type'] = CRM_Utils_Type
::T_STRING
;
169 $params['reply_to']['description'] = 'the Reply-To: header';
170 $params['reply_to']['title'] = 'Reply To';
171 $params['reply_to']['api.aliases'] = ['replyTo'];
172 $params['reply_to']['type'] = CRM_Utils_Type
::T_STRING
;
174 $params['attachments']['description'] = 'email attachments';
175 $params['attachments']['title'] = 'Attachments';
178 $params['is_test']['description'] = 'whether this is a test email (and hence should include the test banner)';
179 $params['is_test']['title'] = 'Is Test';
180 $params['is_test']['api.aliases'] = ['isTest'];
181 $params['is_test']['type'] = CRM_Utils_Type
::T_BOOLEAN
;
183 $params['pdf_filename']['description'] = 'filename of optional PDF version to add as attachment (do not include path)';
184 $params['pdf_filename']['title'] = 'PDF Filename';
185 $params['pdf_filename']['api.aliases'] = ['PDFFilename'];
186 $params['pdf_filename']['type'] = CRM_Utils_Type
::T_STRING
;