4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
13 namespace Civi\WorkflowMessage
;
15 use Civi\Schema\Traits\MagicGetterSetterTrait
;
16 use Civi\WorkflowMessage\Traits\AddressingTrait
;
17 use Civi\WorkflowMessage\Traits\FinalHelperTrait
;
18 use Civi\WorkflowMessage\Traits\ReflectiveWorkflowTrait
;
21 * Generic base-class for describing the inputs for a workflow email template.
23 * @method $this setContactId(int|null $contactId)
24 * @method int|null getContactId()
25 * @method $this setContact(array|null $contact)
26 * @method array|null getContact()
28 * @support template-only
29 * GenericWorkflowMessage should aim for "full" support, but it's prudent to keep
30 * it flexible for the first few months. Consider updating to "full" after Dec 2021.
32 class GenericWorkflowMessage
implements WorkflowMessageInterface
{
34 // Implement getFields(), import(), export(), validate() - All methods based on inspecting class properties (`ReflectionClass`).
35 // Define stub methods exportExtraTokenContext(), exportExtraTplParams(), etc.
36 use ReflectiveWorkflowTrait
;
38 // Implement __call() - Public and protected properties are automatically given a default getter/setter. These may be overridden/customized.
39 use MagicGetterSetterTrait
;
41 // Implement assertValid(), renderTemplate(), sendTemplate() - Sugary stub methods that delegate to real APIs.
44 // Implement setTo(), setReplyTo(), etc
48 * WorkflowMessage constructor.
50 * @param array $imports
51 * List of values to import.
52 * Ex: ['tplParams' => [...tplValues...], 'tokenContext' => [...tokenData...]]
53 * Ex: ['modelProps' => [...classProperties...]]
55 public function __construct(array $imports = []) {
56 WorkflowMessage
::importAll($this, $imports);
60 * The contact receiving this message.
75 * Must provide either 'int $contactId' or 'array $contact'
77 * @param array $errors
78 * @see ReflectiveWorkflowTrait::validate()
80 protected function validateExtra_contact(array &$errors) {
81 if (empty($this->contactId
) && empty($this->contact
['id'])) {
83 'severity' => 'error',
84 'fields' => ['contactId', 'contact'],
85 'name' => 'missingContact',
86 'message' => ts('Message template requires one of these fields (%1)', ['contactId, contact']),
89 if (!empty($this->contactId
) && !empty($this->contact
)) {
91 'severity' => 'warning',
92 'fields' => ['contactId', 'contact'],
93 'name' => 'missingContact',
94 'message' => ts('Passing both (%1) may lead to ambiguous behavior.', ['contactId, contact']),