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] dev/core#2790 Initial creation of pdf trait #21290

Merged
merged 1 commit into from
Aug 28, 2021
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
11 changes: 2 additions & 9 deletions CRM/Activity/Form/Task/PDF.php
Original file line number Diff line number Diff line change
@@ -14,6 +14,8 @@
*/
class CRM_Activity_Form_Task_PDF extends CRM_Activity_Form_Task {

use CRM_Contact_Form_Task_PDFTrait;

/**
* Build all the data structures needed to build the form.
*/
@@ -22,15 +24,6 @@ public function preProcess() {
CRM_Activity_Form_Task_PDFLetterCommon::preProcess($this);
}

/**
* Set defaults for the pdf.
*
* @return array
*/
public function setDefaultValues() {
return CRM_Activity_Form_Task_PDFLetterCommon::setDefaultValues();
}

/**
* Build the form object.
*/
12 changes: 3 additions & 9 deletions CRM/Case/Form/Task/PDF.php
Original file line number Diff line number Diff line change
@@ -19,6 +19,9 @@
* This class provides the functionality to create PDF letter for a group of contacts.
*/
class CRM_Case_Form_Task_PDF extends CRM_Case_Form_Task {

use CRM_Contact_Form_Task_PDFTrait;

/**
* All the existing templates in the system.
*
@@ -40,15 +43,6 @@ public function preProcess() {
$this->setContactIDs();
}

/**
* Set defaults for the pdf.
*
* @return array
*/
public function setDefaultValues() {
return CRM_Contact_Form_Task_PDFLetterCommon::setDefaultValues();
}

/**
* Build the form object.
*/
5 changes: 3 additions & 2 deletions CRM/Contact/Form/Task/PDF.php
Original file line number Diff line number Diff line change
@@ -20,6 +20,8 @@
*/
class CRM_Contact_Form_Task_PDF extends CRM_Contact_Form_Task {

use CRM_Contact_Form_Task_PDFTrait;

/**
* All the existing templates in the system.
*
@@ -72,13 +74,12 @@ public function preProcess() {
* Set default values for the form.
*/
public function setDefaultValues() {
$defaults = [];
$defaults = $this->getPDFDefaultValues();
if (isset($this->_activityId)) {
$params = ['id' => $this->_activityId];
CRM_Activity_BAO_Activity::retrieve($params, $defaults);
$defaults['html_message'] = $defaults['details'] ?? NULL;
}
$defaults = $defaults + CRM_Contact_Form_Task_PDFLetterCommon::setDefaultValues();
return $defaults;
}

41 changes: 41 additions & 0 deletions CRM/Contact/Form/Task/PDFTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

/**
*
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/

/**
* This class provides the common functionality for tasks that send emails.
*/
trait CRM_Contact_Form_Task_PDFTrait {

/**
* Set defaults for the pdf.
*
* @return array
*/
public function setDefaultValues(): array {
return $this->getPDFDefaultValues();
}

/**
* Set default values.
*/
protected function getPDFDefaultValues(): array {
$defaultFormat = CRM_Core_BAO_PdfFormat::getDefaultValues();
$defaultFormat['format_id'] = $defaultFormat['id'];
return $defaultFormat;
}

}
5 changes: 3 additions & 2 deletions CRM/Contribute/Form/Task/PDFLetter.php
Original file line number Diff line number Diff line change
@@ -20,6 +20,8 @@
*/
class CRM_Contribute_Form_Task_PDFLetter extends CRM_Contribute_Form_Task {

use CRM_Contact_Form_Task_PDFTrait;

/**
* All the existing templates in the system.
*
@@ -55,7 +57,7 @@ public function preProcess() {
* @return array
*/
public function setDefaultValues() {
$defaults = [];
$defaults = $this->getPDFDefaultValues();
if (isset($this->_activityId)) {
$params = ['id' => $this->_activityId];
CRM_Activity_BAO_Activity::retrieve($params, $defaults);
@@ -64,7 +66,6 @@ public function setDefaultValues() {
else {
$defaults['thankyou_update'] = 1;
}
$defaults = $defaults + CRM_Contact_Form_Task_PDFLetterCommon::setDefaultValues();
return $defaults;
}

3 changes: 3 additions & 0 deletions CRM/Core/Form/Task/PDFLetterCommon.php
Original file line number Diff line number Diff line change
@@ -171,8 +171,11 @@ public static function buildQuickForm(&$form) {

/**
* Set default values.
*
* @deprecated
*/
public static function setDefaultValues() {
CRM_Core_Error::deprecatedFunctionWarning('no alternative');
$defaultFormat = CRM_Core_BAO_PdfFormat::getDefaultValues();
$defaultFormat['format_id'] = $defaultFormat['id'];
return $defaultFormat;
11 changes: 2 additions & 9 deletions CRM/Event/Form/Task/PDF.php
Original file line number Diff line number Diff line change
@@ -23,6 +23,8 @@
*/
class CRM_Event_Form_Task_PDF extends CRM_Event_Form_Task {

use CRM_Contact_Form_Task_PDFTrait;

/**
* Are we operating in "single mode", i.e. printing letter to one
* specific participant?
@@ -67,15 +69,6 @@ public function postProcess() {
CRM_Contact_Form_Task_PDFLetterCommon::postProcess($this);
}

/**
* Set default values for the form.
*
* @return void
*/
public function setDefaultValues() {
return CRM_Contact_Form_Task_PDFLetterCommon::setDefaultValues();
}

/**
* List available tokens for this form.
*
9 changes: 0 additions & 9 deletions CRM/Member/Form/Task/PDFLetter.php
Original file line number Diff line number Diff line change
@@ -44,15 +44,6 @@ public function preProcess() {
CRM_Contact_Form_Task_PDFLetterCommon::preProcess($this);
}

/**
* Set defaults.
* (non-PHPdoc)
* @see CRM_Core_Form::setDefaultValues()
*/
public function setDefaultValues() {
return CRM_Contact_Form_Task_PDFLetterCommon::setDefaultValues();
}

/**
* Build the form object.
*