return [$formValues, $categories, $html_message, $messageToken, $returnProperties];
}
- /**
- * Process the form after the input has been submitted and validated.
- *
- * @param CRM_Core_Form $form
- *
- * @throws \CRM_Core_Exception
- *
- * @deprecated
- */
- public static function postProcess(&$form): void {
- CRM_Core_Error::deprecatedFunctionWarning('no alternative');
- $formValues = $form->controller->exportValues($form->getName());
- [$formValues, $categories, $html_message, $messageToken, $returnProperties] = self::processMessageTemplate($formValues);
- $html = $activityIds = [];
-
- // CRM-16725 Skip creation of activities if user is previewing their PDF letter(s)
- if (self::isLiveMode($form)) {
- $activityIds = self::createActivities($form, $html_message, $form->_contactIds, $formValues['subject'], CRM_Utils_Array::value('campaign_id', $formValues));
- }
-
- if (!empty($formValues['document_file_path'])) {
- [$html_message, $zip] = CRM_Utils_PDF_Document::unzipDoc($formValues['document_file_path'], $formValues['document_type']);
- }
-
- foreach ($form->_contactIds as $item => $contactId) {
- $caseId = $form->getVar('_caseId');
- if (empty($caseId) && !empty($form->_caseIds[$item])) {
- $caseId = $form->_caseIds[$item];
- }
-
- $tokenHtml = CRM_Core_BAO_MessageTemplate::renderTemplate([
- 'contactId' => $contactId,
- 'messageTemplate' => ['msg_html' => $html_message],
- 'tokenContext' => $caseId ? ['caseId' => $caseId] : [],
- 'disableSmarty' => (!defined('CIVICRM_MAIL_SMARTY') || !CIVICRM_MAIL_SMARTY),
- ])['html'];
-
- $html[] = $tokenHtml;
- }
-
- $tee = NULL;
- if (self::isLiveMode($form) && 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.");
- }
- $tee = CRM_Utils_ConsoleTee::create()->start();
- }
-
- $type = $formValues['document_type'];
- $mimeType = self::getMimeType($type);
- // ^^ Useful side-effect: consistently throws error for unrecognized types.
-
- $fileName = method_exists($form, 'getFileName') ? ($form->getFileName() . '.' . $type) : 'CiviLetter.' . $type;
-
- if ($type === 'pdf') {
- CRM_Utils_PDF_Utils::html2pdf($html, $fileName, FALSE, $formValues);
- }
- elseif (!empty($formValues['document_file_path'])) {
- $fileName = pathinfo($formValues['document_file_path'], PATHINFO_FILENAME) . '.' . $type;
- CRM_Utils_PDF_Document::printDocuments($html, $fileName, $type, $zip);
- }
- else {
- CRM_Utils_PDF_Document::html2doc($html, $fileName, $formValues);
- }
-
- if ($tee) {
- $tee->stop();
- $content = file_get_contents($tee->getFileName(), NULL, NULL, NULL, 5);
- if (empty($content)) {
- throw new \CRM_Core_Exception("Failed to capture document content (type=$type)!");
- }
- foreach ($activityIds as $activityId) {
- civicrm_api3('Attachment', 'create', [
- 'entity_table' => 'civicrm_activity',
- 'entity_id' => $activityId,
- 'name' => $fileName,
- 'mime_type' => $mimeType,
- 'options' => [
- 'move-file' => $tee->getFileName(),
- ],
- ]);
- }
- }
-
- $form->postProcessHook();
-
- CRM_Utils_System::civiExit();
- }
-
/**
* @param CRM_Core_Form $form
* @param string $html_message