[REF] Start transitioning EmailCommon class to a trait
authoreileen <emcnaughton@wikimedia.org>
Tue, 31 Mar 2020 21:08:20 +0000 (10:08 +1300)
committereileen <emcnaughton@wikimedia.org>
Wed, 1 Apr 2020 01:30:23 +0000 (14:30 +1300)
This is a really awful class - I've added a trait &  moved the calls from the various forms to that trait
so the code  on EmailCommon for buildForm is now only called once. I will follow up with more the same

CRM/Activity/Form/Task/Email.php
CRM/Contact/Form/Task/Email.php
CRM/Contact/Form/Task/EmailTrait.php [new file with mode: 0644]
CRM/Contribute/Form/Task/Email.php
CRM/Event/Form/Task/Email.php
CRM/Member/Form/Task/Email.php

index ed83f5863091a69cfbe7f883cc98c1e0694ec6ae..4f548bb7d65b51bb1c33c81c595a5df20fd56446 100644 (file)
  * This class provides the functionality to email a group of contacts.
  */
 class CRM_Activity_Form_Task_Email extends CRM_Activity_Form_Task {
-
-  /**
-   * Are we operating in "single mode", i.e. sending email to one
-   * specific contact?
-   *
-   * @var bool
-   */
-  public $_single = FALSE;
-
-  public $_noEmails = FALSE;
-
-  /**
-   * All the existing templates in the system.
-   *
-   * @var array
-   */
-  public $_templates;
+  use CRM_Contact_Form_Task_EmailTrait;
 
   /**
    * Build all the data structures needed to build the form.
+   *
+   * @throws \CiviCRM_API3_Exception
    */
   public function preProcess() {
     CRM_Contact_Form_Task_EmailCommon::preProcessFromAddress($this);
@@ -49,6 +35,8 @@ class CRM_Activity_Form_Task_Email extends CRM_Activity_Form_Task {
 
   /**
    * Build the form object.
+   *
+   * @throws \CRM_Core_Exception
    */
   public function buildQuickForm() {
     // Enable form element.
@@ -56,13 +44,6 @@ class CRM_Activity_Form_Task_Email extends CRM_Activity_Form_Task {
     CRM_Contact_Form_Task_EmailCommon::buildQuickForm($this);
   }
 
-  /**
-   * Process the form after the input has been submitted and validated.
-   */
-  public function postProcess() {
-    CRM_Contact_Form_Task_EmailCommon::postProcess($this);
-  }
-
   /**
    * List available tokens for this form.
    *
index 4d48e2aa6965c8cb5a732f619cacb6ca8ae6e288..82fb6a3ed686026bd80ec0952f9add72eca2177e 100644 (file)
  */
 class CRM_Contact_Form_Task_Email extends CRM_Contact_Form_Task {
 
-  /**
-   * Are we operating in "single mode".
-   *
-   * Single mode means sending email to one specific contact.
-   *
-   * @var bool
-   */
-  public $_single = FALSE;
-
-  /**
-   * Are we operating in "single mode", i.e. sending email to one
-   * specific contact?
-   *
-   * @var bool
-   */
-  public $_noEmails = FALSE;
-
-  /**
-   * All the existing templates in the system.
-   *
-   * @var array
-   */
-  public $_templates = NULL;
+  use CRM_Contact_Form_Task_EmailTrait;
 
   /**
    * Store "to" contact details.
@@ -139,13 +117,6 @@ class CRM_Contact_Form_Task_Email extends CRM_Contact_Form_Task {
     CRM_Contact_Form_Task_EmailCommon::buildQuickForm($this);
   }
 
-  /**
-   * Process the form after the input has been submitted and validated.
-   */
-  public function postProcess() {
-    CRM_Contact_Form_Task_EmailCommon::postProcess($this);
-  }
-
   /**
    * List available tokens for this form.
    *
diff --git a/CRM/Contact/Form/Task/EmailTrait.php b/CRM/Contact/Form/Task/EmailTrait.php
new file mode 100644 (file)
index 0000000..4450660
--- /dev/null
@@ -0,0 +1,51 @@
+<?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_EmailTrait {
+
+  /**
+   * Are we operating in "single mode", i.e. sending email to one
+   * specific contact?
+   *
+   * @var bool
+   */
+  public $_single = FALSE;
+
+  public $_noEmails = FALSE;
+
+  /**
+   * All the existing templates in the system.
+   *
+   * @var array
+   */
+  public $_templates;
+
+  /**
+   * Process the form after the input has been submitted and validated.
+   *
+   * @throws \CRM_Core_Exception
+   * @throws \CiviCRM_API3_Exception
+   * @throws \Civi\API\Exception\UnauthorizedException
+   */
+  public function postProcess() {
+    CRM_Contact_Form_Task_EmailCommon::postProcess($this);
+  }
+
+}
index d060bd2f18766f0b640c7b137dfd71fe4df182d7..757dbaa4cbb8d2a374a89312e8025028d6dc7378 100644 (file)
  * This class provides the functionality to email a group of contacts.
  */
 class CRM_Contribute_Form_Task_Email extends CRM_Contribute_Form_Task {
-
-  /**
-   * Are we operating in "single mode", i.e. sending email to one
-   * specific contact?
-   *
-   * @var bool
-   */
-  public $_single = FALSE;
-
-  public $_noEmails = FALSE;
-
-  /**
-   * All the existing templates in the system.
-   *
-   * @var array
-   */
-  public $_templates = NULL;
+  use CRM_Contact_Form_Task_EmailTrait;
 
   /**
    * Build all the data structures needed to build the form.
@@ -60,13 +44,6 @@ class CRM_Contribute_Form_Task_Email extends CRM_Contribute_Form_Task {
     CRM_Contact_Form_Task_EmailCommon::buildQuickForm($this);
   }
 
-  /**
-   * Process the form after the input has been submitted and validated.
-   */
-  public function postProcess() {
-    CRM_Contact_Form_Task_EmailCommon::postProcess($this);
-  }
-
   /**
    * List available tokens for this form.
    *
index 3722eced0d3c2522bad07f429d39cf5a254d4aba..428832243d6b07e34bc089f4df83df22edc70e94 100644 (file)
@@ -13,7 +13,6 @@
  *
  * @package CRM
  * @copyright CiviCRM LLC https://civicrm.org/licensing
- * $Id: Email.php 45499 2013-02-08 12:31:05Z kurund $
  */
 
 /**
  * contacts.
  */
 class CRM_Event_Form_Task_Email extends CRM_Event_Form_Task {
-
-  /**
-   * Are we operating in "single mode", i.e. sending email to one
-   * specific contact?
-   *
-   * @var bool
-   */
-  public $_single = FALSE;
-
-  /**
-   * Are we operating in "single mode", i.e. sending email to one
-   * specific contact?
-   *
-   * @var bool
-   */
-  public $_noEmails = FALSE;
-
-  /**
-   * All the existing templates in the system.
-   *
-   * @var array
-   */
-  public $_templates = NULL;
+  use CRM_Contact_Form_Task_EmailTrait;
 
   /**
    * Build all the data structures needed to build the form.
@@ -68,13 +45,6 @@ class CRM_Event_Form_Task_Email extends CRM_Event_Form_Task {
     CRM_Contact_Form_Task_EmailCommon::buildQuickForm($this);
   }
 
-  /**
-   * Process the form after the input has been submitted and validated.
-   */
-  public function postProcess() {
-    CRM_Contact_Form_Task_EmailCommon::postProcess($this);
-  }
-
   /**
    * List available tokens for this form.
    *
index 740cacb223804e2f338ebd43fc278011abfd96b3..bb837547a6427c431985e4c257171d24d3e0bd06 100644 (file)
@@ -13,8 +13,6 @@
  *
  * @package CRM
  * @copyright CiviCRM LLC https://civicrm.org/licensing
- * $Id: Email.php 45499 2013-02-08 12:31:05Z kurund $
- *
  */
 
 /**
  * contacts.
  */
 class CRM_Member_Form_Task_Email extends CRM_Member_Form_Task {
-
-  /**
-   * Are we operating in "single mode", i.e. sending email to one
-   * specific contact?
-   *
-   * @var bool
-   */
-  public $_single = FALSE;
-
-  /**
-   * Are we operating in "single mode", i.e. sending email to one
-   * specific contact?
-   *
-   * @var bool
-   */
-  public $_noEmails = FALSE;
-
-  /**
-   * All the existing templates in the system.
-   *
-   * @var array
-   */
-  public $_templates = NULL;
+  use CRM_Contact_Form_Task_EmailTrait;
 
   /**
    * Build all the data structures needed to build the form.
    *
    * @return void
+   *
+   * @throws \CRM_Core_Exception
+   * @throws \CiviCRM_API3_Exception
    */
   public function preProcess() {
     CRM_Contact_Form_Task_EmailCommon::preProcessFromAddress($this);
@@ -64,8 +43,8 @@ class CRM_Member_Form_Task_Email extends CRM_Member_Form_Task {
   /**
    * Build the form object.
    *
-   *
    * @return void
+   * @throws \CRM_Core_Exception
    */
   public function buildQuickForm() {
     //enable form element
@@ -74,16 +53,6 @@ class CRM_Member_Form_Task_Email extends CRM_Member_Form_Task {
     CRM_Contact_Form_Task_EmailCommon::buildQuickForm($this);
   }
 
-  /**
-   * Process the form after the input has been submitted and validated.
-   *
-   *
-   * @return void
-   */
-  public function postProcess() {
-    CRM_Contact_Form_Task_EmailCommon::postProcess($this);
-  }
-
   /**
    * List available tokens for this form.
    *