[REF] dev/core#2790 move buildForm to pdfTrait
authorEileen McNaughton <emcnaughton@wikimedia.org>
Sat, 28 Aug 2021 05:26:42 +0000 (17:26 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Sat, 28 Aug 2021 05:45:00 +0000 (17:45 +1200)
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

CRM/Activity/Form/Task/PDF.php
CRM/Case/Form/Task/PDF.php
CRM/Contact/Form/Task/PDF.php
CRM/Contact/Form/Task/PDFTrait.php
CRM/Contribute/Form/Task/PDFLetter.php
CRM/Core/Form/Task/PDFLetterCommon.php
CRM/Event/Form/Task/PDF.php
CRM/Member/Form/Task/PDFLetter.php

index f4ce766ea131920df53c4a8ac18c2916e9b470bb..1bf575f349dbeddb8d80252015ed3fab9b9ca452 100644 (file)
@@ -26,9 +26,11 @@ class CRM_Activity_Form_Task_PDF extends CRM_Activity_Form_Task {
 
   /**
    * 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....
index dc0feb9e1d74e0571a38fa7a723b99d74b490929..e0f43f2b913a9b5864e0fd6a5809a50565a14cfc 100644 (file)
@@ -43,13 +43,6 @@ class CRM_Case_Form_Task_PDF extends CRM_Case_Form_Task {
     $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.
    */
index efcdb829e03c0ffbd6880cc14cbc4e96a293b3e3..757ac4833f2b34ad10dca973f53f67acf79576ed 100644 (file)
@@ -89,7 +89,7 @@ class CRM_Contact_Form_Task_PDF extends CRM_Contact_Form_Task {
   public function buildQuickForm() {
     //enable form element
     $this->assign('suppressForm', FALSE);
-    CRM_Contact_Form_Task_PDFLetterCommon::buildQuickForm($this);
+    $this->addPDFElementsToForm();
   }
 
   /**
index 2ebea6694d2763c709aacc16cdceab8910b2ee19..27b7a84fec13e0d468adc11c37e8e7adacc23209 100644 (file)
@@ -38,4 +38,149 @@ trait CRM_Contact_Form_Task_PDFTrait {
     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);
+  }
+
 }
index de315c04b3b73d26c952f5329631cadebf753f40..ae28058164586f9aa76766dba6a6c0dad6fbe909 100644 (file)
@@ -71,6 +71,8 @@ class CRM_Contribute_Form_Task_PDFLetter extends CRM_Contribute_Form_Task {
 
   /**
    * Build the form object.
+   *
+   * @throws \CRM_Core_Exception
    */
   public function buildQuickForm() {
     //enable form element
@@ -82,7 +84,7 @@ class CRM_Contribute_Form_Task_PDFLetter extends CRM_Contribute_Form_Task {
 
     // 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'));
index 9433cb7bbbad4832fb17f7109100b7465febf94f..1ddc2cdd1bac2e83082f0cdd46a85900ee6ce03f 100644 (file)
@@ -36,10 +36,13 @@ class CRM_Core_Form_Task_PDFLetterCommon {
   /**
    * 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();
 
index 94efe16be3f8bd8f966449dd4bb8c9db7ddb0aa7..43341aaf12f89d6439360185ed33ff42a3f32597 100644 (file)
@@ -55,13 +55,6 @@ class CRM_Event_Form_Task_PDF extends CRM_Event_Form_Task {
     $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.
    */
index fef15f13d89883cc95e6c8e8ba2632d464de655f..fd73a19dc3c1113f55a747d03c3488daf03dbb29 100644 (file)
@@ -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.
    *
@@ -49,11 +51,12 @@ class CRM_Member_Form_Task_PDFLetter extends CRM_Member_Form_Task {
    *
    *
    * @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();
   }
 
   /**