From c97bfeff55b0d2faeb6dccffbe2e19a2b7208d6c Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Wed, 1 Sep 2021 07:14:46 +1200 Subject: [PATCH] [REF] dev/core#2790 move preProcess static to the trait --- CRM/Case/Form/Task/PDF.php | 2 +- CRM/Contact/Form/Task/PDF.php | 2 +- CRM/Contact/Form/Task/PDFLetterCommon.php | 3 +++ CRM/Contact/Form/Task/PDFTrait.php | 18 ++++++++++++++++++ CRM/Contribute/Form/Task/PDFLetter.php | 2 +- CRM/Event/Form/Task/PDF.php | 2 +- CRM/Member/Form/Task/PDFLetter.php | 2 +- 7 files changed, 26 insertions(+), 5 deletions(-) diff --git a/CRM/Case/Form/Task/PDF.php b/CRM/Case/Form/Task/PDF.php index e0f43f2b91..65954ea272 100644 --- a/CRM/Case/Form/Task/PDF.php +++ b/CRM/Case/Form/Task/PDF.php @@ -37,7 +37,7 @@ class CRM_Case_Form_Task_PDF extends CRM_Case_Form_Task { * Build all the data structures needed to build the form. */ public function preProcess() { - CRM_Contact_Form_Task_PDFLetterCommon::preProcess($this); + $this->preProcessPDF(); $this->skipOnHold = $this->skipDeceased = FALSE; parent::preProcess(); $this->setContactIDs(); diff --git a/CRM/Contact/Form/Task/PDF.php b/CRM/Contact/Form/Task/PDF.php index 757ac4833f..884819bdb4 100644 --- a/CRM/Contact/Form/Task/PDF.php +++ b/CRM/Contact/Form/Task/PDF.php @@ -41,7 +41,7 @@ class CRM_Contact_Form_Task_PDF extends CRM_Contact_Form_Task { public function preProcess() { $this->skipOnHold = $this->skipDeceased = FALSE; - CRM_Contact_Form_Task_PDFLetterCommon::preProcess($this); + $this->preProcessPDF(); // store case id if present $this->_caseId = CRM_Utils_Request::retrieve('caseid', 'CommaSeparatedIntegers', $this, FALSE); diff --git a/CRM/Contact/Form/Task/PDFLetterCommon.php b/CRM/Contact/Form/Task/PDFLetterCommon.php index 44716b1047..bb0c2dcef5 100644 --- a/CRM/Contact/Form/Task/PDFLetterCommon.php +++ b/CRM/Contact/Form/Task/PDFLetterCommon.php @@ -39,9 +39,12 @@ class CRM_Contact_Form_Task_PDFLetterCommon extends CRM_Core_Form_Task_PDFLetter /** * Build all the data structures needed to build the form. * + * @deprecated + * * @param CRM_Core_Form $form */ public static function preProcess(&$form) { + CRM_Core_Error::deprecatedFunctionWarning('no alternative'); $defaults = []; $form->_fromEmails = CRM_Core_BAO_Email::getFromEmail(); if (is_numeric(key($form->_fromEmails))) { diff --git a/CRM/Contact/Form/Task/PDFTrait.php b/CRM/Contact/Form/Task/PDFTrait.php index 27b7a84fec..9ac741c0a1 100644 --- a/CRM/Contact/Form/Task/PDFTrait.php +++ b/CRM/Contact/Form/Task/PDFTrait.php @@ -183,4 +183,22 @@ trait CRM_Contact_Form_Task_PDFTrait { $form->addFormRule(['CRM_Core_Form_Task_PDFLetterCommon', 'formRule'], $form); } + /** + * Prepare form. + */ + public function preProcessPDF(): void { + $form = $this; + $defaults = []; + $form->_fromEmails = CRM_Core_BAO_Email::getFromEmail(); + if (is_numeric(key($form->_fromEmails))) { + $emailID = (int) key($form->_fromEmails); + $defaults = CRM_Core_BAO_Email::getEmailSignatureDefaults($emailID); + } + if (!Civi::settings()->get('allow_mail_from_logged_in_contact')) { + $defaults['from_email_address'] = current(CRM_Core_BAO_Domain::getNameAndEmail(FALSE, TRUE)); + } + $form->setDefaults($defaults); + $form->setTitle('Print/Merge Document'); + } + } diff --git a/CRM/Contribute/Form/Task/PDFLetter.php b/CRM/Contribute/Form/Task/PDFLetter.php index 9941415900..330e1e2d59 100644 --- a/CRM/Contribute/Form/Task/PDFLetter.php +++ b/CRM/Contribute/Form/Task/PDFLetter.php @@ -38,7 +38,7 @@ class CRM_Contribute_Form_Task_PDFLetter extends CRM_Contribute_Form_Task { */ public function preProcess() { $this->skipOnHold = $this->skipDeceased = FALSE; - CRM_Contact_Form_Task_PDFLetterCommon::preProcess($this); + $this->preProcessPDF(); parent::preProcess(); $this->assign('single', $this->isSingle()); } diff --git a/CRM/Event/Form/Task/PDF.php b/CRM/Event/Form/Task/PDF.php index 43341aaf12..9ce1baed9c 100644 --- a/CRM/Event/Form/Task/PDF.php +++ b/CRM/Event/Form/Task/PDF.php @@ -46,7 +46,7 @@ class CRM_Event_Form_Task_PDF extends CRM_Event_Form_Task { * Build all the data structures needed to build the form. */ public function preProcess() { - CRM_Contact_Form_Task_PDFLetterCommon::preProcess($this); + $this->preProcessPDF(); parent::preProcess(); // we have all the participant ids, so now we get the contact ids diff --git a/CRM/Member/Form/Task/PDFLetter.php b/CRM/Member/Form/Task/PDFLetter.php index fd73a19dc3..92e8471473 100644 --- a/CRM/Member/Form/Task/PDFLetter.php +++ b/CRM/Member/Form/Task/PDFLetter.php @@ -43,7 +43,7 @@ class CRM_Member_Form_Task_PDFLetter extends CRM_Member_Form_Task { $this->skipOnHold = $this->skipDeceased = FALSE; parent::preProcess(); $this->setContactIDs(); - CRM_Contact_Form_Task_PDFLetterCommon::preProcess($this); + $this->preProcessPDF(); } /** -- 2.25.1