From 5d2000d114c62ea107514f7c55cad3f35a5a50e8 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 28 Mar 2023 16:59:38 +1300 Subject: [PATCH] Fix incorrect redirect when saving with bad config Since the config is checked after saving we want to go to the edit form, not the new form --- CRM/Admin/Form/PaymentProcessor.php | 55 +++++++++++++++++------------ 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/CRM/Admin/Form/PaymentProcessor.php b/CRM/Admin/Form/PaymentProcessor.php index 641dac4c5a..c5b5263c52 100644 --- a/CRM/Admin/Form/PaymentProcessor.php +++ b/CRM/Admin/Form/PaymentProcessor.php @@ -89,34 +89,14 @@ class CRM_Admin_Form_PaymentProcessor extends CRM_Admin_Form { */ public function preProcess() { parent::preProcess(); + CRM_Core_Session::singleton()->pushUserContext('civicrm/admin/paymentProcessor?reset=1'); $this->setPaymentProcessorTypeID(); $this->setPaymentProcessor(); $this->assign('ppType', $this->_paymentProcessorType); $this->assign('ppTypeName', $this->_paymentProcessorDAO->name); - if ($this->_id) { - $refreshURL = CRM_Utils_System::url('civicrm/admin/paymentProcessor/edit', - "reset=1&action=update&id={$this->_id}", - FALSE, NULL, FALSE - ); - } - else { - $refreshURL = CRM_Utils_System::url('civicrm/admin/paymentProcessor/edit', - 'reset=1&action=add', - FALSE, NULL, FALSE - ); - } - - //CRM-4129 - $destination = CRM_Utils_Request::retrieve('civicrmDestination', 'String', $this); - if ($destination) { - $destination = urlencode($destination); - $refreshURL .= "&civicrmDestination=$destination"; - } - - $this->refreshURL = $refreshURL; - $this->assign('refreshURL', $refreshURL); + $this->assign('refreshURL', $this->getRefreshURL()); $this->assign('is_recur', $this->_paymentProcessorDAO->is_recur); @@ -404,12 +384,14 @@ class CRM_Admin_Form_PaymentProcessor extends CRM_Admin_Form { } $this->updatePaymentProcessor($values, $domainID, TRUE); $paymentProcessorID = $this->updatePaymentProcessor($values, $domainID, FALSE); + // Set the ID so that if it fails checkConfig the refreshUrl takes it into account. + $this->_id = $paymentProcessorID; $processor = Civi\Payment\System::singleton()->getById($paymentProcessorID); $errors = $processor->checkConfig(); if ($errors) { CRM_Core_Session::setStatus($errors, ts('Payment processor configuration invalid'), 'error'); Civi::log()->error('Payment processor configuration invalid: ' . $errors); - CRM_Core_Session::singleton()->pushUserContext($this->refreshURL); + CRM_Core_Session::singleton()->pushUserContext($this->getRefreshURL()); } else { CRM_Core_Session::setStatus(ts('Payment processor %1 has been saved.', [1 => "{$values['title']}"]), ts('Saved'), 'success'); @@ -506,4 +488,31 @@ class CRM_Admin_Form_PaymentProcessor extends CRM_Admin_Form { $this->_paymentProcessorDAO->find(TRUE); } + /** + * @return string + * @throws \CRM_Core_Exception + */ + private function getRefreshURL(): string { + if ($this->_id) { + $refreshURL = CRM_Utils_System::url('civicrm/admin/paymentProcessor/edit', + "reset=1&action=update&id={$this->_id}", + FALSE, NULL, FALSE + ); + } + else { + $refreshURL = CRM_Utils_System::url('civicrm/admin/paymentProcessor/edit', + 'reset=1&action=add', + FALSE, NULL, FALSE + ); + } + + //CRM-4129 + $destination = CRM_Utils_Request::retrieve('civicrmDestination', 'String', $this); + if ($destination) { + $destination = urlencode($destination); + $refreshURL .= "&civicrmDestination=$destination"; + } + return $refreshURL; + } + } -- 2.25.1