From 8a432af6a3c23115603cdcd65931950b514ccd01 Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 1 Apr 2020 10:08:20 +1300 Subject: [PATCH] [REF] Start transitioning EmailCommon class to a trait 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 | 29 +++------------- CRM/Contact/Form/Task/Email.php | 31 +---------------- CRM/Contact/Form/Task/EmailTrait.php | 51 ++++++++++++++++++++++++++++ CRM/Contribute/Form/Task/Email.php | 25 +------------- CRM/Event/Form/Task/Email.php | 32 +---------------- CRM/Member/Form/Task/Email.php | 41 +++------------------- 6 files changed, 64 insertions(+), 145 deletions(-) create mode 100644 CRM/Contact/Form/Task/EmailTrait.php diff --git a/CRM/Activity/Form/Task/Email.php b/CRM/Activity/Form/Task/Email.php index ed83f5863091..4f548bb7d65b 100644 --- a/CRM/Activity/Form/Task/Email.php +++ b/CRM/Activity/Form/Task/Email.php @@ -19,26 +19,12 @@ * 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 @@ public function preProcess() { /** * Build the form object. + * + * @throws \CRM_Core_Exception */ public function buildQuickForm() { // Enable form element. @@ -56,13 +44,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. * diff --git a/CRM/Contact/Form/Task/Email.php b/CRM/Contact/Form/Task/Email.php index 4d48e2aa6965..82fb6a3ed686 100644 --- a/CRM/Contact/Form/Task/Email.php +++ b/CRM/Contact/Form/Task/Email.php @@ -20,29 +20,7 @@ */ 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 @@ 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. * diff --git a/CRM/Contact/Form/Task/EmailTrait.php b/CRM/Contact/Form/Task/EmailTrait.php new file mode 100644 index 000000000000..4450660c0723 --- /dev/null +++ b/CRM/Contact/Form/Task/EmailTrait.php @@ -0,0 +1,51 @@ +