From 752cee47213094c29b8e6ae5d0b20f0800520d80 Mon Sep 17 00:00:00 2001 From: eileen Date: Sun, 26 May 2019 11:47:41 +1200 Subject: [PATCH] [REF] extract isLiveMode I'm closing https://github.com/civicrm/civicrm-core/pull/13369 as it is stale, but I figure it makes sense to pull out this extraction from it. I think the PR then alters the button names taken into account but I'm not seeking to fix here, just to do the extraction --- CRM/Contact/Form/Task/PDFLetterCommon.php | 28 ++++++++++++++++++----- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/CRM/Contact/Form/Task/PDFLetterCommon.php b/CRM/Contact/Form/Task/PDFLetterCommon.php index b52b24d767..c5b8439801 100644 --- a/CRM/Contact/Form/Task/PDFLetterCommon.php +++ b/CRM/Contact/Form/Task/PDFLetterCommon.php @@ -126,17 +126,12 @@ class CRM_Contact_Form_Task_PDFLetterCommon extends CRM_Core_Form_Task_PDFLetter public static function postProcess(&$form) { $formValues = $form->controller->exportValues($form->getName()); list($formValues, $categories, $html_message, $messageToken, $returnProperties) = self::processMessageTemplate($formValues); - $buttonName = $form->controller->getButtonName(); $skipOnHold = isset($form->skipOnHold) ? $form->skipOnHold : FALSE; $skipDeceased = isset($form->skipDeceased) ? $form->skipDeceased : TRUE; $html = $activityIds = []; - // CRM-21255 - Hrm, CiviCase 4+5 seem to report buttons differently... - $c = $form->controller->container(); - $isLiveMode = ($buttonName == '_qf_PDF_upload') || isset($c['values']['PDF']['buttons']['_qf_PDF_upload']); - // CRM-16725 Skip creation of activities if user is previewing their PDF letter(s) - if ($isLiveMode) { + if (self::isLiveMode($form)) { $activityIds = self::createActivities($form, $html_message, $form->_contactIds, $formValues['subject'], CRM_Utils_Array::value('campaign_id', $formValues)); } @@ -348,4 +343,25 @@ class CRM_Contact_Form_Task_PDFLetterCommon extends CRM_Core_Form_Task_PDFLetter return Civi::$statics[__CLASS__]['token_categories']; } + /** + * Is the form in live mode (as opposed to being run as a preview). + * + * Returns true if the user has clicked the Download Document button on a + * Print/Merge Document (PDF Letter) search task form, or false if the Preview + * button was clicked. + * + * @param CRM_Core_Form $form + * + * @return bool + * TRUE if the Download Document button was clicked (also defaults to TRUE + * if the form controller does not exist), else FALSE + */ + protected static function isLiveMode($form) { + // CRM-21255 - Hrm, CiviCase 4+5 seem to report buttons differently... + $buttonName = $form->controller->getButtonName(); + $c = $form->controller->container(); + $isLiveMode = ($buttonName == '_qf_PDF_upload') || isset($c['values']['PDF']['buttons']['_qf_PDF_upload']); + return $isLiveMode; + } + } -- 2.25.1