Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REF] extract isLiveMode #14336

Merged
merged 1 commit into from
May 26, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions CRM/Contact/Form/Task/PDFLetterCommon.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,12 @@ public static function processMessageTemplate($formValues) {
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));
}

Expand Down Expand Up @@ -348,4 +343,25 @@ protected static function getTokenCategories() {
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;
}

}