From 592172f75f1a69b4c8bf50fede9d3f7137072ae7 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Mon, 23 Oct 2017 18:11:36 -0700 Subject: [PATCH] CRM-21255 - PDFLetterCommon - Detect buttons in new popup style Overview -------------- Suppose you enable the extension `org.civicrm.civicase`, set the option `recordGeneratedLetters=combined-attached`, and create a PDF based on the instructions in [CRM-21255](https://issues.civicrm.org/jira/browse/CRM-21255). The PDF generator tries to determine whether the clicked the button labeled "Preview" or "Download Document". This works correctly with the CiviCase 4 popup mechanism, but in the CiviCase 5 popup mechanism it doesn't work. Before -------------- When you click the "Download Document" button, the operates in a quasi-preview mode and fails to create any activities. This eventually leads to a crash because the expected activities are missing. After -------------- The controller uses a more accurate check which correctly differentiates "Preview" and "Download Document" on both CiviCase 4+5. Comments -------------- I'm not a huge fan of this patch, but it helps demonstrate the problem+solution. @colemanw, perhaps there's a better way to make the buttons function consistently in CiviCase 4+5? --- CRM/Contact/Form/Task/PDFLetterCommon.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/CRM/Contact/Form/Task/PDFLetterCommon.php b/CRM/Contact/Form/Task/PDFLetterCommon.php index 71df969cb3..ce7e33a8f1 100644 --- a/CRM/Contact/Form/Task/PDFLetterCommon.php +++ b/CRM/Contact/Form/Task/PDFLetterCommon.php @@ -363,8 +363,12 @@ class CRM_Contact_Form_Task_PDFLetterCommon { $skipDeceased = isset($form->skipDeceased) ? $form->skipDeceased : TRUE; $html = $activityIds = array(); + // 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 ($buttonName == '_qf_PDF_upload') { + if ($isLiveMode) { // This seems silly, but the old behavior was to first check `_cid` // and then use the provided `$contactIds`. Probably not even necessary, @@ -418,7 +422,7 @@ class CRM_Contact_Form_Task_PDFLetterCommon { } $tee = NULL; - if (Civi::settings()->get('recordGeneratedLetters') === 'combined-attached') { + if ($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."); } -- 2.25.1