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 class GenericWorkflowMessage
implements WorkflowMessageInterface
{
30 // Implement getFields(), import(), export(), validate() - All methods based on inspecting class properties (`ReflectionClass`).
31 // Define stub methods exportExtraTokenContext(), exportExtraTplParams(), etc.
32 use ReflectiveWorkflowTrait
;
34 // Implement __call() - Public and protected properties are automatically given a default getter/setter. These may be overridden/customized.
35 use MagicGetterSetterTrait
;
37 // Implement assertValid(), renderTemplate(), sendTemplate() - Sugary stub methods that delegate to real APIs.
40 // Implement setTo(), setReplyTo(), etc
44 * WorkflowMessage constructor.
46 * @param array $imports
47 * List of values to import.
48 * Ex: ['tplParams' => [...tplValues...], 'tokenContext' => [...tokenData...]]
49 * Ex: ['modelProps' => [...classProperties...]]
51 public function __construct(array $imports = []) {
52 WorkflowMessage
::importAll($this, $imports);
56 * The contact receiving this message.
71 * Must provide either 'int $contactId' or 'array $contact'
73 * @param array $errors
74 * @see ReflectiveWorkflowTrait::validate()
76 protected function validateExtra_contact(array &$errors) {
77 if (empty($this->contactId
) && empty($this->contact
['id'])) {
79 'severity' => 'error',
80 'fields' => ['contactId', 'contact'],
81 'name' => 'missingContact',
82 'message' => ts('Message template requires one of these fields (%1)', ['contactId, contact']),
85 if (!empty($this->contactId
) && !empty($this->contact
)) {
87 'severity' => 'warning',
88 'fields' => ['contactId', 'contact'],
89 'name' => 'missingContact',
90 'message' => ts('Passing both (%1) may lead to ambiguous behavior.', ['contactId, contact']),