Merge pull request #24203 from colemanw/fixTagFilter553
[civicrm-core.git] / Civi / Api4 / WorkflowMessage.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
6 | |
7 | This work is published under the GNU AGPLv3 license with some |
8 | permitted exceptions and without any warranty. For full license |
9 | and copyright information, see https://civicrm.org/licensing |
10 +--------------------------------------------------------------------+
11 */
12
13 /**
14 *
15 * @package CRM
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 */
18
19 namespace Civi\Api4;
20
21 /**
22 * A WorkflowMessage describes the inputs to an automated email messages, and it
23 * allows you to render or preview the content fo automated email messages.
24 *
25 * For example, when a constituent donates online, CiviContribute uses the
26 * `contribution_online_receipt` workflow message. This expects certain inputs
27 * (eg `contactId` and `contributionId`) and supports certain tokens
28 * (eg `{contribution.total_amount}`).
29 *
30 * WorkflowMessages are related to MessageTemplates (by way of
31 * `WorkflowMessage.name`<=>`MessageTemplate.workflow_name`).
32 * The WorkflowMessage defines the _contract_ or _processing_ of the
33 * message, and the MessageTemplate defines the _literal prose_. The prose
34 * would change frequently (eg for different deployments, locales, timeframes,
35 * and other whims), but contract would change conservatively (eg with a
36 * code-update and with some attention to backward-compatibility/change-management).
37 *
38 * @searchable none
39 * @since 5.43
40 * @package Civi\Api4
41 */
42 class WorkflowMessage extends Generic\AbstractEntity {
43
44 /**
45 * @param bool $checkPermissions
46 * @return Generic\BasicGetAction
47 */
48 public static function get($checkPermissions = TRUE) {
49 return (new Generic\BasicGetAction(__CLASS__, __FUNCTION__, function ($get) {
50 return \Civi\WorkflowMessage\WorkflowMessage::getWorkflowSpecs();
51 }))->setCheckPermissions($checkPermissions);
52 }
53
54 /**
55 * @param bool $checkPermissions
56 *
57 * @return \Civi\Api4\Action\WorkflowMessage\Render
58 */
59 public static function render($checkPermissions = TRUE) {
60 return (new Action\WorkflowMessage\Render(__CLASS__, __FUNCTION__))
61 ->setCheckPermissions($checkPermissions);
62 }
63
64 /**
65 * @param bool $checkPermissions
66 * @return Generic\BasicGetFieldsAction
67 */
68 public static function getTemplateFields($checkPermissions = TRUE) {
69 return (new Action\WorkflowMessage\GetTemplateFields(__CLASS__, __FUNCTION__))
70 ->setCheckPermissions($checkPermissions);
71 }
72
73 /**
74 * @param bool $checkPermissions
75 * @return Generic\BasicGetFieldsAction
76 */
77 public static function getFields($checkPermissions = TRUE) {
78 return (new Generic\BasicGetFieldsAction(__CLASS__, __FUNCTION__, function() {
79 return [
80 [
81 'name' => 'name',
82 'title' => 'Name',
83 'data_type' => 'String',
84 ],
85 [
86 'name' => 'group',
87 'title' => 'Group',
88 'data_type' => 'String',
89 ],
90 [
91 'name' => 'class',
92 'title' => 'Class',
93 'data_type' => 'String',
94 ],
95 [
96 'name' => 'description',
97 'title' => 'Description',
98 'data_type' => 'String',
99 ],
100 [
101 'name' => 'support',
102 'title' => 'Support Level',
103 'options' => [
104 'experimental' => ts('Experimental: Message may change substantively with no special communication or facilitation.'),
105 'template-only' => ts('Template Support: Changes affecting the content of the message-template will get active support/facilitation.'),
106 'full' => ts('Full Support: All changes affecting message-templates or message-senders will get active support/facilitation.'),
107 ],
108 'data_type' => 'String',
109 ],
110 ];
111 }))->setCheckPermissions($checkPermissions);
112 }
113
114 public static function permissions() {
115 return [
116 'meta' => ['access CiviCRM'],
117 'default' => ['administer CiviCRM'],
118 'render' => [
119 // nested array = OR
120 [
121 'edit message templates',
122 'edit user-driven message templates',
123 'edit system workflow message templates',
124 'render templates',
125 ],
126 ],
127 ];
128 }
129
130 /**
131 * @inheritDoc
132 */
133 public static function getInfo() {
134 $info = parent::getInfo();
135 $info['primary_key'] = ['name'];
136 return $info;
137 }
138
139 }