Merge pull request #18286 from sunilpawar/ui_30
[civicrm-core.git] / CRM / Contact / Form / Task / Email.php
index 4d48e2aa6965c8cb5a732f619cacb6ca8ae6e288..911a060adb0d7655a80dd022bf56ec703384d927 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;
-
-  /**
-   * Store "to" contact details.
-   * @var array
-   */
-  public $_toContactDetails = [];
-
-  /**
-   * Store all selected contact id's, that includes to, cc and bcc contacts
-   * @var array
-   */
-  public $_allContactIds = [];
-
-  /**
-   * Store only "to" contact ids.
-   * @var array
-   */
-  public $_toContactIds = [];
-
-  /**
-   * Store only "cc" contact ids.
-   * @var array
-   */
-  public $_ccContactIds = [];
-
-  /**
-   * Store only "bcc" contact ids.
-   * @var array
-   */
-  public $_bccContactIds = [];
+  use CRM_Contact_Form_Task_EmailTrait;
 
   /**
    * Build all the data structures needed to build the form.
@@ -81,6 +29,8 @@ class CRM_Contact_Form_Task_Email extends CRM_Contact_Form_Task {
    * @throws \CRM_Core_Exception
    */
   public function preProcess() {
+    // @todo - more of the handling in this function should be move to the trait. Notably the title part is
+    //  not set on other forms that share the trait.
     // store case id if present
     $this->_caseId = CRM_Utils_Request::retrieve('caseid', 'String', $this, FALSE);
     $this->_context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this);
@@ -116,40 +66,27 @@ class CRM_Contact_Form_Task_Email extends CRM_Contact_Form_Task {
     if ($this->_context === 'search') {
       $this->_single = TRUE;
     }
-    CRM_Contact_Form_Task_EmailCommon::preProcessFromAddress($this);
-
-    if (!$cid && $this->_context !== 'standalone') {
-      parent::preProcess();
-    }
-
-    $this->assign('single', $this->_single);
-    if (CRM_Core_Permission::check('administer CiviCRM')) {
-      $this->assign('isAdmin', 1);
+    if ($cid || $this->_context === 'standalone') {
+      // When search context is false the parent pre-process is not set. That avoids it changing the
+      // redirect url & attempting to set the search params of the form. It may have only
+      // historical significance.
+      $this->setIsSearchContext(FALSE);
     }
+    $this->traitPreProcess();
   }
 
   /**
-   * Build the form object.
-   */
-  public function buildQuickForm() {
-    //enable form element
-    $this->assign('suppressForm', FALSE);
-    $this->assign('emailTask', TRUE);
-
-    CRM_Contact_Form_Task_EmailCommon::buildQuickForm($this);
-  }
-
-  /**
-   * Process the form after the input has been submitted and validated.
+   * Stub function  as EmailTrait calls this.
+   *
+   * @todo move some code from preProcess into here.
    */
-  public function postProcess() {
-    CRM_Contact_Form_Task_EmailCommon::postProcess($this);
-  }
+  public function setContactIDs() {}
 
   /**
    * List available tokens for this form.
    *
    * @return array
+   * @throws \CRM_Core_Exception
    */
   public function listTokens() {
     $tokens = CRM_Core_SelectValues::contactTokens();