From 2537798f6be69fb162018d07a0cc2da9dc9f129e Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 28 Sep 2021 23:39:33 +1300 Subject: [PATCH] [REF] stop passing form into createActivities This function is now an OO function - so we can make it protected & stop passing form in --- CRM/Contact/Form/Task/PDFTrait.php | 17 ++++++++--------- CRM/Contribute/Form/Task/PDFLetter.php | 2 +- CRM/Member/Form/Task/PDFLetter.php | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/CRM/Contact/Form/Task/PDFTrait.php b/CRM/Contact/Form/Task/PDFTrait.php index 890246d84097..b12d51ebc1a8 100644 --- a/CRM/Contact/Form/Task/PDFTrait.php +++ b/CRM/Contact/Form/Task/PDFTrait.php @@ -84,7 +84,7 @@ public function addPDFElementsToForm(): void { ts('Paper Size'), [0 => ts('- default -')] + CRM_Core_BAO_PaperSize::getList(TRUE), FALSE, - ['onChange' => "selectPaper( this.value ); showUpdateFormatChkBox();"] + ['onChange' => 'selectPaper( this.value ); showUpdateFormatChkBox();'] ); $form->add( 'select', @@ -92,7 +92,7 @@ public function addPDFElementsToForm(): void { ts('Orientation'), CRM_Core_BAO_PdfFormat::getPageOrientations(), FALSE, - ['onChange' => "updatePaperDimensions(); showUpdateFormatChkBox();"] + ['onChange' => 'updatePaperDimensions(); showUpdateFormatChkBox();'] ); $form->add( 'select', @@ -225,13 +225,13 @@ protected function isLiveMode(): bool { */ public function postProcess(): void { $form = $this; - $formValues = $form->controller->exportValues($form->getName()); - [$formValues, $html_message, $messageToken, $returnProperties] = $this->processMessageTemplate($formValues); + $formValues = $this->controller->exportValues($this->getName()); + [$formValues, $html_message] = $this->processMessageTemplate($formValues); $html = $activityIds = []; // CRM-16725 Skip creation of activities if user is previewing their PDF letter(s) if ($this->isLiveMode()) { - $activityIds = $this->createActivities($form, $html_message, $form->_contactIds, $formValues['subject'], CRM_Utils_Array::value('campaign_id', $formValues)); + $activityIds = $this->createActivities($html_message, $form->_contactIds, $formValues['subject'], CRM_Utils_Array::value('campaign_id', $formValues)); } if (!empty($formValues['document_file_path'])) { @@ -257,7 +257,7 @@ public function postProcess(): void { $tee = NULL; if ($this->isLiveMode() && Civi::settings()->get('recordGeneratedLetters') === 'combined-attached') { if (count($activityIds) !== 1) { - throw new CRM_Core_Exception("When recordGeneratedLetters=combined-attached, there should only be one activity."); + throw new CRM_Core_Exception('When recordGeneratedLetters=combined-attached, there should only be one activity.'); } $tee = CRM_Utils_ConsoleTee::create()->start(); } @@ -326,7 +326,6 @@ protected function getMimeType($type) { } /** - * @param CRM_Core_Form $form * @param string $html_message * @param array $contactIds * @param string $subject @@ -340,8 +339,8 @@ protected function getMimeType($type) { * * @throws CRM_Core_Exception */ - public function createActivities($form, $html_message, $contactIds, $subject, $campaign_id, $perContactHtml = []) { - + protected function createActivities($html_message, $contactIds, $subject, $campaign_id, $perContactHtml = []) { + $form = $this; $activityParams = [ 'subject' => $subject, 'campaign_id' => $campaign_id, diff --git a/CRM/Contribute/Form/Task/PDFLetter.php b/CRM/Contribute/Form/Task/PDFLetter.php index 2804ae236baa..828227dc665b 100644 --- a/CRM/Contribute/Form/Task/PDFLetter.php +++ b/CRM/Contribute/Form/Task/PDFLetter.php @@ -235,7 +235,7 @@ public function postProcess() { $contactIds = array_keys($contacts); // CRM-16725 Skip creation of activities if user is previewing their PDF letter(s) if ($this->isLiveMode()) { - $this->createActivities($this, $html_message, $contactIds, CRM_Utils_Array::value('subject', $formValues, ts('Thank you letter')), CRM_Utils_Array::value('campaign_id', $formValues), $contactHtml); + $this->createActivities($html_message, $contactIds, CRM_Utils_Array::value('subject', $formValues, ts('Thank you letter')), CRM_Utils_Array::value('campaign_id', $formValues), $contactHtml); } $html = array_diff_key($html, $emailedHtml); diff --git a/CRM/Member/Form/Task/PDFLetter.php b/CRM/Member/Form/Task/PDFLetter.php index 4b8436ddcd7a..308070d7e214 100644 --- a/CRM/Member/Form/Task/PDFLetter.php +++ b/CRM/Member/Form/Task/PDFLetter.php @@ -97,7 +97,7 @@ public function postProcessMembers($membershipIDs, $skipOnHold, $skipDeceased, $ $messageToken, $html_message ); - $form->createActivities($form, $html_message, $contactIDs, $formValues['subject'], CRM_Utils_Array::value('campaign_id', $formValues)); + $form->createActivities($html_message, $contactIDs, $formValues['subject'], CRM_Utils_Array::value('campaign_id', $formValues)); CRM_Utils_PDF_Utils::html2pdf($html, $this->getFileName() . '.pdf', FALSE, $formValues); $form->postProcessHook();