From: Eileen McNaughton Date: Wed, 13 May 2015 06:20:41 +0000 (+1200) Subject: Put common preProcess actions into parent class X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=42e8b05c6be509d418967459f4da4ffb1d6b352b;p=civicrm-core.git Put common preProcess actions into parent class 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 --- diff --git a/CRM/Contribute/Form/AbstractEditPayment.php b/CRM/Contribute/Form/AbstractEditPayment.php index 9c39f2b842..b698b30c9c 100644 --- a/CRM/Contribute/Form/AbstractEditPayment.php +++ b/CRM/Contribute/Form/AbstractEditPayment.php @@ -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 */ diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index 3ac6267c51..961b0ec68f 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -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 diff --git a/CRM/Contribute/Task.php b/CRM/Contribute/Task.php index d4d095a46d..c7f9b8256f 100644 --- a/CRM/Contribute/Task.php +++ b/CRM/Contribute/Task.php @@ -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( diff --git a/CRM/Event/Form/Participant.php b/CRM/Event/Form/Participant.php index 0930d5b95c..1bd751a848 100644 --- a/CRM/Event/Form/Participant.php +++ b/CRM/Event/Form/Participant.php @@ -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; diff --git a/CRM/Member/Form.php b/CRM/Member/Form.php index 1a1901f930..da11de287d 100644 --- a/CRM/Member/Form.php +++ b/CRM/Member/Form.php @@ -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) { diff --git a/CRM/Member/Form/Membership.php b/CRM/Member/Form/Membership.php index f4124732c8..bd4555f501 100644 --- a/CRM/Member/Form/Membership.php +++ b/CRM/Member/Form/Membership.php @@ -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) { diff --git a/CRM/Member/Form/MembershipRenewal.php b/CRM/Member/Form/MembershipRenewal.php index 8f19fdfc34..bf652428fb 100644 --- a/CRM/Member/Form/MembershipRenewal.php +++ b/CRM/Member/Form/MembershipRenewal.php @@ -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(); } /**