From e5777079dd19ac8bbca99bf2f3efed26bcfa8142 Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Sun, 10 May 2020 11:39:14 +0100 Subject: [PATCH] [REF] Extract setUserContext on contribution form & cleanup on backend add membership form --- CRM/Contribute/Form/Contribution.php | 55 ++++++++++++++++------------ CRM/Member/Form/Membership.php | 23 ++++++------ 2 files changed, 43 insertions(+), 35 deletions(-) diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index 09f05ba0bd..d453df3a7c 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -951,30 +951,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP CRM_Core_Error::statusBounce($e->getMessage(), $urlParams, ts('Payment Processor Error')); } - $session = CRM_Core_Session::singleton(); - $buttonName = $this->controller->getButtonName(); - if ($this->_context == 'standalone') { - if ($buttonName == $this->getButtonName('upload', 'new')) { - $session->replaceUserContext(CRM_Utils_System::url('civicrm/contribute/add', - 'reset=1&action=add&context=standalone' - )); - } - else { - $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view', - "reset=1&cid={$this->_contactID}&selectedChild=contribute" - )); - } - } - elseif ($this->_context == 'contribution' && $this->_mode && $buttonName == $this->getButtonName('upload', 'new')) { - $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view/contribution', - "reset=1&action=add&context={$this->_context}&cid={$this->_contactID}&mode={$this->_mode}" - )); - } - elseif ($buttonName == $this->getButtonName('upload', 'new')) { - $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view/contribution', - "reset=1&action=add&context={$this->_context}&cid={$this->_contactID}" - )); - } + $this->setUserContext(); //store contribution ID if not yet set (on create) if (empty($this->_id) && !empty($contribution->id)) { @@ -1814,4 +1791,34 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP } } + /** + * Set context in session + */ + public function setUserContext(): void { + $session = CRM_Core_Session::singleton(); + $buttonName = $this->controller->getButtonName(); + if ($this->_context == 'standalone') { + if ($buttonName == $this->getButtonName('upload', 'new')) { + $session->replaceUserContext(CRM_Utils_System::url('civicrm/contribute/add', + 'reset=1&action=add&context=standalone' + )); + } + else { + $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view', + "reset=1&cid={$this->_contactID}&selectedChild=contribute" + )); + } + } + elseif ($this->_context == 'contribution' && $this->_mode && $buttonName == $this->getButtonName('upload', 'new')) { + $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view/contribution', + "reset=1&action=add&context={$this->_context}&cid={$this->_contactID}&mode={$this->_mode}" + )); + } + elseif ($buttonName == $this->getButtonName('upload', 'new')) { + $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view/contribution', + "reset=1&action=add&context={$this->_context}&cid={$this->_contactID}" + )); + } + } + } diff --git a/CRM/Member/Form/Membership.php b/CRM/Member/Form/Membership.php index 88e21e4025..3c98b8570b 100644 --- a/CRM/Member/Form/Membership.php +++ b/CRM/Member/Form/Membership.php @@ -1780,23 +1780,24 @@ class CRM_Member_Form_Membership extends CRM_Member_Form { $buttonName = $this->controller->getButtonName(); $session = CRM_Core_Session::singleton(); - if ($this->_context === 'standalone') { - if ($buttonName == $this->getButtonName('upload', 'new')) { - $session->replaceUserContext(CRM_Utils_System::url('civicrm/member/add', + if ($buttonName == $this->getButtonName('upload', 'new')) { + if ($this->_context === 'standalone') { + $url = CRM_Utils_System::url('civicrm/member/add', 'reset=1&action=add&context=standalone' - )); + ); } else { - $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view', - "reset=1&cid={$this->_contactID}&selectedChild=member" - )); + $url = CRM_Utils_System::url('civicrm/contact/view/membership', + "reset=1&action=add&context=membership&cid={$this->_contactID}" + ); } } - elseif ($buttonName == $this->getButtonName('upload', 'new')) { - $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view/membership', - "reset=1&action=add&context=membership&cid={$this->_contactID}" - )); + else { + $url = CRM_Utils_System::url('civicrm/contact/view', + "reset=1&cid={$this->_contactID}&selectedChild=member" + ); } + $session->replaceUserContext($url); } /** -- 2.25.1