From f34aa7324308d22f1650f28f695344f7b0406d4b Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Wed, 6 Oct 2021 22:22:30 +1300 Subject: [PATCH] Adjust getRows result to have schema as a key It becomes too complex to handle in email trait otherwise --- CRM/Case/Form/Task.php | 2 +- CRM/Contact/Form/Task/PDF.php | 2 +- CRM/Contact/Form/Task/PDFTrait.php | 4 ++-- CRM/Core/Form/Task.php | 2 +- CRM/Event/Form/Task.php | 13 ++++++++----- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/CRM/Case/Form/Task.php b/CRM/Case/Form/Task.php index 6bebba8cf7..863a3c58f5 100644 --- a/CRM/Case/Form/Task.php +++ b/CRM/Case/Form/Task.php @@ -76,7 +76,7 @@ class CRM_Case_Form_Task extends CRM_Core_Form_Task { if (empty($caseID) && !empty($this->_caseIds[$index])) { $caseID = $this->_caseIds[$index]; } - $rows[] = ['contactId' => $contactID, 'caseId' => $caseID]; + $rows[] = ['contact_id' => $contactID, 'schema' => ['caseId' => $caseID, 'contactId' => $contactID]]; } return $rows; } diff --git a/CRM/Contact/Form/Task/PDF.php b/CRM/Contact/Form/Task/PDF.php index 66f1138eb5..8c91685113 100644 --- a/CRM/Contact/Form/Task/PDF.php +++ b/CRM/Contact/Form/Task/PDF.php @@ -127,7 +127,7 @@ class CRM_Contact_Form_Task_PDF extends CRM_Contact_Form_Task { if (empty($caseID) && !empty($this->_caseIds[$index])) { $caseID = $this->_caseIds[$index]; } - $rows[] = ['contactId' => $contactID, 'caseId' => $caseID]; + $rows[] = ['contact_id' => $contactID, 'schema' => ['caseId' => $caseID, 'contactId' => $contactID]]; } return $rows; } diff --git a/CRM/Contact/Form/Task/PDFTrait.php b/CRM/Contact/Form/Task/PDFTrait.php index 2cfa43c87b..dae3544153 100644 --- a/CRM/Contact/Form/Task/PDFTrait.php +++ b/CRM/Contact/Form/Task/PDFTrait.php @@ -239,9 +239,9 @@ trait CRM_Contact_Form_Task_PDFTrait { foreach ($this->getRows() as $row) { $tokenHtml = CRM_Core_BAO_MessageTemplate::renderTemplate([ - 'contactId' => $row['contactId'], + 'contactId' => $row['contact_id'], 'messageTemplate' => ['msg_html' => $html_message], - 'tokenContext' => array_merge($row, ['schema' => $this->getTokenSchema()]), + 'tokenContext' => ['schema' => $row['schema']], 'disableSmarty' => (!defined('CIVICRM_MAIL_SMARTY') || !CIVICRM_MAIL_SMARTY), ])['html']; diff --git a/CRM/Core/Form/Task.php b/CRM/Core/Form/Task.php index 81ed62d15c..5e8501a6ce 100644 --- a/CRM/Core/Form/Task.php +++ b/CRM/Core/Form/Task.php @@ -367,7 +367,7 @@ SELECT contact_id protected function getRows(): array { $rows = []; foreach ($this->getContactIDs() as $contactID) { - $rows[] = ['contactId' => $contactID]; + $rows[] = ['schema' => ['contactId' => $contactID]]; } return $rows; } diff --git a/CRM/Event/Form/Task.php b/CRM/Event/Form/Task.php index 20704e0e93..a23da4c6b5 100644 --- a/CRM/Event/Form/Task.php +++ b/CRM/Event/Form/Task.php @@ -122,7 +122,7 @@ class CRM_Event_Form_Task extends CRM_Core_Form_Task { return $this->_contactIds; } foreach ($this->getRows() as $row) { - $this->_contactIds[] = $row['contactId']; + $this->_contactIds[] = $row['contact_id']; } return $this->_contactIds; } @@ -158,7 +158,7 @@ class CRM_Event_Form_Task extends CRM_Core_Form_Task { * * @throws \API_Exception */ - public function getRows(): array { + protected function getRows(): array { if (empty($this->rows)) { // checkPermissions set to false - in case form is bypassing in some way. $participants = Participant::get(FALSE) @@ -166,9 +166,12 @@ class CRM_Event_Form_Task extends CRM_Core_Form_Task { ->setSelect(['id', 'contact_id'])->execute(); foreach ($participants as $participant) { $this->rows[] = [ - // We map to this funky format for the token processor :-( - 'contactId' => $participant['contact_id'], - 'participantId' => $participant['id'], + 'contact_id' => $participant['contact_id'], + 'participant_id' => $participant['id'], + 'schema' => [ + 'contactId' => $participant['contact_id'], + 'participantId' => $participant['id'], + ], ]; } } -- 2.25.1