From 8bfe8c6d7856a76f71734943c941cc3c9144a644 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 14 Jul 2021 12:07:12 -0700 Subject: [PATCH] GenericWorkflowMessage - Accept contactId or contact record --- .../GenericWorkflowMessage.php | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/Civi/WorkflowMessage/GenericWorkflowMessage.php b/Civi/WorkflowMessage/GenericWorkflowMessage.php index 10a8b4373f..0423dca179 100644 --- a/Civi/WorkflowMessage/GenericWorkflowMessage.php +++ b/Civi/WorkflowMessage/GenericWorkflowMessage.php @@ -21,6 +21,8 @@ use Civi\WorkflowMessage\Traits\ReflectiveWorkflowTrait; * * @method $this setContactId(int|null $contactId) * @method int|null getContactId() + * @method $this setContact(array|null $contact) + * @method array|null getContact() */ class GenericWorkflowMessage implements WorkflowMessageInterface { @@ -49,9 +51,41 @@ class GenericWorkflowMessage implements WorkflowMessageInterface { /** * The contact receiving this message. * - * @var int + * @var int|null * @scope tokenContext + * @fkEntity Contact */ protected $contactId; + /** + * @var array|null + * @scope tokenContext + */ + protected $contact; + + /** + * Must provide either 'int $contactId' or 'array $contact' + * + * @param array $errors + * @see ReflectiveWorkflowTrait::validate() + */ + protected function validateExtra_contact(array &$errors) { + if (empty($this->contactId) && empty($this->contact['id'])) { + $errors[] = [ + 'severity' => 'error', + 'fields' => ['contactId', 'contact'], + 'name' => 'missingContact', + 'message' => ts('Message template requires one of these fields (%1)', ['contactId, contact']), + ]; + } + if (!empty($this->contactId) && !empty($this->contact)) { + $errors[] = [ + 'severity' => 'warning', + 'fields' => ['contactId', 'contact'], + 'name' => 'missingContact', + 'message' => ts('Passing both (%1) may lead to ambiguous behavior.', ['contactId, contact']), + ]; + } + } + } -- 2.25.1