Skip to content

Commit

Permalink
[REF] Start transitioning EmailCommon class to a trait
Browse files Browse the repository at this point in the history
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
  • Loading branch information
eileenmcnaughton committed Mar 31, 2020
1 parent 8742ba9 commit ecb8ebe
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 42 deletions.
12 changes: 5 additions & 7 deletions CRM/Activity/Form/Task/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* This class provides the functionality to email a group of contacts.
*/
class CRM_Activity_Form_Task_Email extends CRM_Activity_Form_Task {
use CRM_Contact_Form_Task_EmailTrait;

/**
* Are we operating in "single mode", i.e. sending email to one
Expand All @@ -39,6 +40,8 @@ class CRM_Activity_Form_Task_Email extends CRM_Activity_Form_Task {

/**
* Build all the data structures needed to build the form.
*
* @throws \CiviCRM_API3_Exception
*/
public function preProcess() {
CRM_Contact_Form_Task_EmailCommon::preProcessFromAddress($this);
Expand All @@ -49,20 +52,15 @@ public function preProcess() {

/**
* Build the form object.
*
* @throws \CRM_Core_Exception
*/
public function buildQuickForm() {
// Enable form element.
$this->assign('emailTask', TRUE);
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.
*
Expand Down
7 changes: 0 additions & 7 deletions CRM/Contact/Form/Task/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,6 @@ public function buildQuickForm() {
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.
*
Expand Down
34 changes: 34 additions & 0 deletions CRM/Contact/Form/Task/EmailTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?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 {

/**
* 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);
}

}
8 changes: 1 addition & 7 deletions CRM/Contribute/Form/Task/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* This class provides the functionality to email a group of contacts.
*/
class CRM_Contribute_Form_Task_Email extends CRM_Contribute_Form_Task {
use CRM_Contact_Form_Task_EmailTrait;

/**
* Are we operating in "single mode", i.e. sending email to one
Expand Down Expand Up @@ -60,13 +61,6 @@ public function buildQuickForm() {
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.
*
Expand Down
9 changes: 1 addition & 8 deletions CRM/Event/Form/Task/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
*
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
* $Id: Email.php 45499 2013-02-08 12:31:05Z kurund $
*/

/**
* This class provides the functionality to email a group of
* contacts.
*/
class CRM_Event_Form_Task_Email extends CRM_Event_Form_Task {
use CRM_Contact_Form_Task_EmailTrait;

/**
* Are we operating in "single mode", i.e. sending email to one
Expand Down Expand Up @@ -68,13 +68,6 @@ public function buildQuickForm() {
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.
*
Expand Down
18 changes: 5 additions & 13 deletions CRM/Member/Form/Task/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@
*
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
* $Id: Email.php 45499 2013-02-08 12:31:05Z kurund $
*
*/

/**
* This class provides the functionality to email a group of
* contacts.
*/
class CRM_Member_Form_Task_Email extends CRM_Member_Form_Task {
use CRM_Contact_Form_Task_EmailTrait;

/**
* Are we operating in "single mode", i.e. sending email to one
Expand Down Expand Up @@ -50,6 +49,9 @@ class CRM_Member_Form_Task_Email extends CRM_Member_Form_Task {
* 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);
Expand All @@ -64,8 +66,8 @@ public function preProcess() {
/**
* Build the form object.
*
*
* @return void
* @throws \CRM_Core_Exception
*/
public function buildQuickForm() {
//enable form element
Expand All @@ -74,16 +76,6 @@ public function buildQuickForm() {
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.
*
Expand Down

0 comments on commit ecb8ebe

Please sign in to comment.