Put common preProcess actions into parent class
authorEileen McNaughton <eileen@fuzion.co.nz>
Wed, 13 May 2015 06:20:41 +0000 (18:20 +1200)
committerEileen McNaughton <eileen@fuzion.co.nz>
Wed, 13 May 2015 12:41:26 +0000 (00:41 +1200)
Note that this switches the Participant form to calling
      CRM_Contact_Form_Task::preProcessCommon($this);
      rather than parent::preProcess();
      I think this may remove the need for the twisted inheritance
      but haven't set AbstractEditPayment back to inherit from
      CRM_Core_Form
      which is more desirable.y

towards consolidating onto parent preProcess
but the whole cdtype seems to block tidy up - although cdType seems to be a misimplementation -
in that there should be a custom data type form called for ajax rather than putting it on every form

r

r

CRM/Contribute/Form/AbstractEditPayment.php
CRM/Contribute/Form/Contribution.php
CRM/Contribute/Task.php
CRM/Event/Form/Participant.php
CRM/Member/Form.php
CRM/Member/Form/Membership.php
CRM/Member/Form/MembershipRenewal.php

index 9c39f2b842125ca1c0c288ff170b37f891e290b2..b698b30c9cf91c9cc48b673603e3b5e1fb433ee4 100644 (file)
@@ -204,6 +204,16 @@ class CRM_Contribute_Form_AbstractEditPayment extends CRM_Contact_Form_Task {
    */
   public $billingFieldSets = array();
 
+  /**
+   * Pre process function with common actions.
+   */
+  public function preProcess() {
+    $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
+    $this->assign('contactID', $this->_contactID);
+
+    $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add');
+  }
+
   /**
    * @param int $id
    */
index 3ac6267c51e35d9e7cf6290e0df76848cf946a54..961b0ec68f311b9ef128f1feba5f2359f2aec219 100644 (file)
@@ -233,12 +233,10 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
    * Set variables up before form is built.
    */
   public function preProcess() {
-
     // Check permission for action.
     if (!CRM_Core_Permission::checkActionPermission('CiviContribute', $this->_action)) {
       CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
     }
-
     // @todo - if anyone ever figures out what this _cdType subroutine is about
     // (or even if it still applies) please add comments!!!!!!!!!!
     $this->_cdType = CRM_Utils_Array::value('type', $_GET);
@@ -249,6 +247,8 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
       return;
     }
 
+    parent::preProcess();
+
     $this->_formType = CRM_Utils_Array::value('formType', $_GET);
 
     // Get price set id.
@@ -259,11 +259,6 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
     // Get the pledge payment id
     $this->_ppID = CRM_Utils_Request::retrieve('ppid', 'Positive', $this);
 
-    // Get the contact id
-    $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
-
-    // Get the action.
-    $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add');
     $this->assign('action', $this->_action);
 
     // Get the contribution id if update
index d4d095a46d8c305738492170eb168306dbbbdf6e..c7f9b8256f448c4da1fc8a68e94c6b57806bf47f 100644 (file)
@@ -62,7 +62,7 @@ class CRM_Contribute_Task {
    * @return array
    *   the set of tasks for a group of contacts
    */
-  public static function &tasks() {
+  public static function tasks() {
     if (!(self::$_tasks)) {
       self::$_tasks = array(
         1 => array(
index 0930d5b95c1a9e8e633ef76d4ad6fa132fe39f45..1bd751a84818dfd247aa6915cdf6f0c07e64aa10 100644 (file)
@@ -329,7 +329,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
           $this->_action = CRM_Core_Action::COPY;
           break;
       }
-      parent::preProcess();
+      CRM_Contact_Form_Task::preProcessCommon($this);
 
       $this->_single = FALSE;
       $this->_contactId = NULL;
index 1a1901f930ce01bba1d5ae6b7c54c6fb6b6fc650..da11de287d8cede35505a3361b21674daf4789bb 100644 (file)
@@ -59,8 +59,12 @@ class CRM_Member_Form extends CRM_Contribute_Form_AbstractEditPayment {
   protected $_fromEmails = array();
 
   public function preProcess() {
+    // Check for edit permission.
+    if (!CRM_Core_Permission::checkActionPermission('CiviMember', $this->_action)) {
+      CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
+    }
+    parent::preProcess();
     $params = array();
-    $params['action'] = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add');
     $params['context'] = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE, 'membership');
     $params['id'] = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     $params['mode'] = CRM_Utils_Request::retrieve('mode', 'String', $this);
@@ -69,7 +73,6 @@ class CRM_Member_Form extends CRM_Contribute_Form_AbstractEditPayment {
 
     $this->assign('context', $this->_context);
     $this->assign('membershipMode', $this->_mode);
-    $this->assign('contactID', $this->_contactID);
   }
 
   /**
@@ -85,14 +88,13 @@ class CRM_Member_Form extends CRM_Contribute_Form_AbstractEditPayment {
     if (isset($this->_id)) {
       $params = array('id' => $this->_id);
       CRM_Member_BAO_Membership::retrieve($params, $defaults);
-    }
-
-    if (isset($defaults['minimum_fee'])) {
-      $defaults['minimum_fee'] = CRM_Utils_Money::format($defaults['minimum_fee'], NULL, '%a');
-    }
+      if (isset($defaults['minimum_fee'])) {
+        $defaults['minimum_fee'] = CRM_Utils_Money::format($defaults['minimum_fee'], NULL, '%a');
+      }
 
-    if (isset($defaults['status'])) {
-      $this->assign('membershipStatus', $defaults['status']);
+      if (isset($defaults['status'])) {
+        $this->assign('membershipStatus', $defaults['status']);
+      }
     }
 
     if ($this->_action & CRM_Core_Action::ADD) {
@@ -111,8 +113,6 @@ class CRM_Member_Form extends CRM_Contribute_Form_AbstractEditPayment {
 
   /**
    * Build the form object.
-   *
-   * @return void
    */
   public function buildQuickForm() {
     if ($this->_mode) {
index f4124732c8e6b8d19ac8e8dcbed7be53b686b9d3..bd4555f501f4db8beca7f2bd2dbb8605272632fd 100644 (file)
@@ -184,11 +184,6 @@ class CRM_Member_Form_Membership extends CRM_Member_Form {
     $this->set('priceSetId', $this->_priceSetId);
     $this->assign('priceSetId', $this->_priceSetId);
 
-    // check for edit permission
-    if (!CRM_Core_Permission::checkActionPermission('CiviMember', $this->_action)) {
-      CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
-    }
-
     if ($this->_action & CRM_Core_Action::DELETE) {
       $contributionID = CRM_Member_BAO_Membership::getMembershipContributionId($this->_id);
       // check delete permission for contribution
@@ -429,8 +424,6 @@ class CRM_Member_Form_Membership extends CRM_Member_Form {
 
   /**
    * Build the form object.
-   *
-   * @return void
    */
   public function buildQuickForm() {
     if ($this->_cdType) {
index 8f19fdfc3464d86a8f29ba35f9d4ccc22d532417..bf652428fb6b1c95d4e29d69e9a59856261bea03 100644 (file)
@@ -107,7 +107,7 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form {
     $this->assign('cdType', FALSE);
     if ($this->_cdType) {
       $this->assign('cdType', TRUE);
-      CRM_Custom_Form_CustomData::preProcess($this);
+      return CRM_Custom_Form_CustomData::preProcess($this);
     }
 
     parent::preProcess();
@@ -148,8 +148,6 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form {
     }
 
     CRM_Utils_System::setTitle(ts('Renew Membership'));
-
-    parent::preProcess();
   }
 
   /**