Skip to content

Commit

Permalink
[REF] dev/core#2790 move buildForm to pdfTrait
Browse files Browse the repository at this point in the history
This moves the buildForm function over the pdfTrait

I note that some of the functions have

I wonder if they all should  - I suspect so
  • Loading branch information
eileenmcnaughton committed Aug 28, 2021
1 parent 0aac04a commit 053c1a4
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 18 deletions.
4 changes: 3 additions & 1 deletion CRM/Activity/Form/Task/PDF.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ public function preProcess() {

/**
* Build the form object.
*
* @throws \CRM_Core_Exception
*/
public function buildQuickForm() {
CRM_Activity_Form_Task_PDFLetterCommon::buildQuickForm($this);
$this->addPDFElementsToForm();
// Remove types other than pdf as they are not working (have never worked) and don't want fix
// for them to block pdf.
// @todo debug & fix....
Expand Down
7 changes: 0 additions & 7 deletions CRM/Case/Form/Task/PDF.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@ public function preProcess() {
$this->setContactIDs();
}

/**
* Build the form object.
*/
public function buildQuickForm() {
CRM_Contact_Form_Task_PDFLetterCommon::buildQuickForm($this);
}

/**
* Process the form after the input has been submitted and validated.
*/
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contact/Form/Task/PDF.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function setDefaultValues() {
public function buildQuickForm() {
//enable form element
$this->assign('suppressForm', FALSE);
CRM_Contact_Form_Task_PDFLetterCommon::buildQuickForm($this);
$this->addPDFElementsToForm();
}

/**
Expand Down
145 changes: 145 additions & 0 deletions CRM/Contact/Form/Task/PDFTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,149 @@ protected function getPDFDefaultValues(): array {
return $defaultFormat;
}

/**
* Build the form object.
*
* @throws \CRM_Core_Exception
*/
public function buildQuickForm(): void {
$this->addPDFElementsToForm();
}

/**
* Build the form object.
*
* @throws \CRM_Core_Exception
*/
public function addPDFElementsToForm(): void {
$form = $this;
// This form outputs a file so should never be submitted via ajax
$form->preventAjaxSubmit();

//Added for CRM-12682: Add activity subject and campaign fields
CRM_Campaign_BAO_Campaign::addCampaign($form);
$form->add(
'text',
'subject',
ts('Activity Subject'),
['size' => 45, 'maxlength' => 255],
FALSE
);

// Added for core#2121,
// To support sending a custom pdf filename before downloading.
$form->addElement('hidden', 'pdf_file_name');

$form->addSelect('format_id', [
'label' => ts('Select Format'),
'placeholder' => ts('Default'),
'entity' => 'message_template',
'field' => 'pdf_format_id',
'option_url' => 'civicrm/admin/pdfFormats',
]);
$form->add(
'select',
'paper_size',
ts('Paper Size'),
[0 => ts('- default -')] + CRM_Core_BAO_PaperSize::getList(TRUE),
FALSE,
['onChange' => "selectPaper( this.value ); showUpdateFormatChkBox();"]
);
$form->add(
'select',
'orientation',
ts('Orientation'),
CRM_Core_BAO_PdfFormat::getPageOrientations(),
FALSE,
['onChange' => "updatePaperDimensions(); showUpdateFormatChkBox();"]
);
$form->add(
'select',
'metric',
ts('Unit of Measure'),
CRM_Core_BAO_PdfFormat::getUnits(),
FALSE,
['onChange' => "selectMetric( this.value );"]
);
$form->add(
'text',
'margin_left',
ts('Left Margin'),
['size' => 8, 'maxlength' => 8, 'onkeyup' => "showUpdateFormatChkBox();"],
TRUE
);
$form->add(
'text',
'margin_right',
ts('Right Margin'),
['size' => 8, 'maxlength' => 8, 'onkeyup' => "showUpdateFormatChkBox();"],
TRUE
);
$form->add(
'text',
'margin_top',
ts('Top Margin'),
['size' => 8, 'maxlength' => 8, 'onkeyup' => "showUpdateFormatChkBox();"],
TRUE
);
$form->add(
'text',
'margin_bottom',
ts('Bottom Margin'),
['size' => 8, 'maxlength' => 8, 'onkeyup' => "showUpdateFormatChkBox();"],
TRUE
);

$config = CRM_Core_Config::singleton();
/** CRM-15883 Suppressing Stationery path field until we switch from DOMPDF to a library that supports it.
* if ($config->wkhtmltopdfPath == FALSE) {
* $form->add(
* 'text',
* 'stationery',
* ts('Stationery (relative path to PDF you wish to use as the background)'),
* array('size' => 25, 'maxlength' => 900, 'onkeyup' => "showUpdateFormatChkBox();"),
* FALSE
* );
* }
*/
$form->add('checkbox', 'bind_format', ts('Always use this Page Format with the selected Template'));
$form->add('checkbox', 'update_format', ts('Update Page Format (this will affect all templates that use this format)'));

$form->assign('useThisPageFormat', ts('Always use this Page Format with the new template?'));
$form->assign('useSelectedPageFormat', ts('Should the new template always use the selected Page Format?'));
$form->assign('totalSelectedContacts', !is_null($form->_contactIds) ? count($form->_contactIds) : 0);

$form->add('select', 'document_type', ts('Document Type'), CRM_Core_SelectValues::documentFormat());

$documentTypes = implode(',', CRM_Core_SelectValues::documentApplicationType());
$form->addElement('file', "document_file", 'Upload Document', 'size=30 maxlength=255 accept="' . $documentTypes . '"');
$form->addUploadElement("document_file");

CRM_Mailing_BAO_Mailing::commonCompose($form);

$buttons = [];
if ($form->get('action') != CRM_Core_Action::VIEW) {
$buttons[] = [
'type' => 'upload',
'name' => ts('Download Document'),
'isDefault' => TRUE,
'icon' => 'fa-download',
];
$buttons[] = [
'type' => 'submit',
'name' => ts('Preview'),
'subName' => 'preview',
'icon' => 'fa-search',
'isDefault' => FALSE,
];
}
$buttons[] = [
'type' => 'cancel',
'name' => $form->get('action') == CRM_Core_Action::VIEW ? ts('Done') : ts('Cancel'),
];
$form->addButtons($buttons);

$form->addFormRule(['CRM_Core_Form_Task_PDFLetterCommon', 'formRule'], $form);
}

}
4 changes: 3 additions & 1 deletion CRM/Contribute/Form/Task/PDFLetter.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public function setDefaultValues() {

/**
* Build the form object.
*
* @throws \CRM_Core_Exception
*/
public function buildQuickForm() {
//enable form element
Expand All @@ -82,7 +84,7 @@ public function buildQuickForm() {

// Contribute PDF tasks allow you to email as well, so we need to add email address to those forms
$this->add('select', 'from_email_address', ts('From Email Address'), $this->_fromEmails, TRUE);
CRM_Core_Form_Task_PDFLetterCommon::buildQuickForm($this);
$this->addPDFElementsToForm();

// specific need for contributions
$this->add('static', 'more_options_header', NULL, ts('Thank-you Letter Options'));
Expand Down
3 changes: 3 additions & 0 deletions CRM/Core/Form/Task/PDFLetterCommon.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ public static function preProcess(&$form) {
/**
* Build the form object.
*
* @deprecated
*
* @var CRM_Core_Form $form
* @throws \CRM_Core_Exception
*/
public static function buildQuickForm(&$form) {
CRM_Core_Error::deprecatedFunctionWarning('no supported alternative for non-core code');
// This form outputs a file so should never be submitted via ajax
$form->preventAjaxSubmit();

Expand Down
7 changes: 0 additions & 7 deletions CRM/Event/Form/Task/PDF.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,6 @@ public function preProcess() {
$this->assign('single', $this->_single);
}

/**
* Build the form object.
*/
public function buildQuickForm() {
CRM_Contact_Form_Task_PDFLetterCommon::buildQuickForm($this);
}

/**
* Process the form after the input has been submitted and validated.
*/
Expand Down
5 changes: 4 additions & 1 deletion CRM/Member/Form/Task/PDFLetter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
*/
class CRM_Member_Form_Task_PDFLetter extends CRM_Member_Form_Task {

use CRM_Contact_Form_Task_PDFTrait;

/**
* All the existing templates in the system.
*
Expand Down Expand Up @@ -49,11 +51,12 @@ public function preProcess() {
*
*
* @return void
* @throws \CRM_Core_Exception
*/
public function buildQuickForm() {
//enable form element
$this->assign('suppressForm', FALSE);
CRM_Contact_Form_Task_PDFLetterCommon::buildQuickForm($this);
$this->addPDFElementsToForm();
}

/**
Expand Down

0 comments on commit 053c1a4

Please sign in to comment.