From e4b857f8fabb7ed3b304c43dd7e6a7439cfba7a5 Mon Sep 17 00:00:00 2001 From: "Matthew Wire (MJW Consulting)" Date: Sat, 22 Jun 2019 12:25:04 +0100 Subject: [PATCH] Add a helper function to ensure we always set the correct tab for manage events --- CRM/Event/Form/ManageEvent.php | 15 +++++++++++++++ CRM/Event/Form/ManageEvent/EventInfo.php | 2 +- CRM/Event/Form/ManageEvent/Fee.php | 2 +- CRM/Event/Form/ManageEvent/Location.php | 2 +- CRM/Event/Form/ManageEvent/Registration.php | 2 +- CRM/Event/Form/ManageEvent/Repeat.php | 2 +- CRM/Event/Form/ManageEvent/ScheduleReminders.php | 2 +- CRM/Event/Form/ManageEvent/TabHeader.php | 2 -- CRM/Friend/Form/Event.php | 2 +- CRM/PCP/Form/Event.php | 2 +- 10 files changed, 23 insertions(+), 10 deletions(-) diff --git a/CRM/Event/Form/ManageEvent.php b/CRM/Event/Form/ManageEvent.php index 9e065f4cc1..17c9b9e78d 100644 --- a/CRM/Event/Form/ManageEvent.php +++ b/CRM/Event/Form/ManageEvent.php @@ -100,6 +100,21 @@ class CRM_Event_Form_ManageEvent extends CRM_Core_Form { return 'create'; } + /** + * Set the active tab + * + * @param string $default + * + * @throws \CRM_Core_Exception + */ + public function setSelectedChild($default = NULL) { + $selectedChild = CRM_Utils_Request::retrieve('selectedChild', 'Alphanumeric', $this, FALSE, $default); + if (!empty($selectedChild)) { + $this->set('selectedChild', $selectedChild); + $this->assign('selectedChild', $selectedChild); + } + } + /** * Set variables up before form is built. */ diff --git a/CRM/Event/Form/ManageEvent/EventInfo.php b/CRM/Event/Form/ManageEvent/EventInfo.php index db2d950951..0bf756f151 100644 --- a/CRM/Event/Form/ManageEvent/EventInfo.php +++ b/CRM/Event/Form/ManageEvent/EventInfo.php @@ -46,7 +46,7 @@ class CRM_Event_Form_ManageEvent_EventInfo extends CRM_Event_Form_ManageEvent { */ public function preProcess() { parent::preProcess(); - $this->assign('selectedChild', 'settings'); + $this->setSelectedChild('settings'); $entityID = $this->_id ?: $this->_templateId; if ($entityID) { diff --git a/CRM/Event/Form/ManageEvent/Fee.php b/CRM/Event/Form/ManageEvent/Fee.php index ddc1c2da06..46420b809a 100644 --- a/CRM/Event/Form/ManageEvent/Fee.php +++ b/CRM/Event/Form/ManageEvent/Fee.php @@ -62,7 +62,7 @@ class CRM_Event_Form_ManageEvent_Fee extends CRM_Event_Form_ManageEvent { */ public function preProcess() { parent::preProcess(); - $this->assign('selectedChild', 'fee'); + $this->setSelectedChild('fee'); } /** diff --git a/CRM/Event/Form/ManageEvent/Location.php b/CRM/Event/Form/ManageEvent/Location.php index b33eafe0a4..7e2c8a8889 100644 --- a/CRM/Event/Form/ManageEvent/Location.php +++ b/CRM/Event/Form/ManageEvent/Location.php @@ -73,7 +73,7 @@ class CRM_Event_Form_ManageEvent_Location extends CRM_Event_Form_ManageEvent { */ public function preProcess() { parent::preProcess(); - $this->assign('selectedChild', 'location'); + $this->setSelectedChild('location'); $this->_values = $this->get('values'); if ($this->_id && empty($this->_values)) { diff --git a/CRM/Event/Form/ManageEvent/Registration.php b/CRM/Event/Form/ManageEvent/Registration.php index 0c62605713..0c03c4f9f9 100644 --- a/CRM/Event/Form/ManageEvent/Registration.php +++ b/CRM/Event/Form/ManageEvent/Registration.php @@ -55,7 +55,7 @@ class CRM_Event_Form_ManageEvent_Registration extends CRM_Event_Form_ManageEvent $this->_profileBottomNumAdd = CRM_Utils_Array::value('addProfileNumAdd', $_GET, 0); parent::preProcess(); - $this->assign('selectedChild', 'registration'); + $this->setSelectedChild('registration'); $this->assign('addProfileBottom', $this->_addProfileBottom); $this->assign('profileBottomNum', $this->_profileBottomNum); diff --git a/CRM/Event/Form/ManageEvent/Repeat.php b/CRM/Event/Form/ManageEvent/Repeat.php index f02716591d..9aad1cd161 100644 --- a/CRM/Event/Form/ManageEvent/Repeat.php +++ b/CRM/Event/Form/ManageEvent/Repeat.php @@ -26,7 +26,7 @@ class CRM_Event_Form_ManageEvent_Repeat extends CRM_Event_Form_ManageEvent { public function preProcess() { parent::preProcess(); - $this->assign('selectedChild', 'repeat'); + $this->setSelectedChild('repeat'); $this->assign('currentEventId', $this->_id); $checkParentExistsForThisId = CRM_Core_BAO_RecurringEntity::getParentFor($this->_id, 'civicrm_event'); diff --git a/CRM/Event/Form/ManageEvent/ScheduleReminders.php b/CRM/Event/Form/ManageEvent/ScheduleReminders.php index 483f275de6..4129564e57 100644 --- a/CRM/Event/Form/ManageEvent/ScheduleReminders.php +++ b/CRM/Event/Form/ManageEvent/ScheduleReminders.php @@ -47,7 +47,7 @@ class CRM_Event_Form_ManageEvent_ScheduleReminders extends CRM_Event_Form_Manage */ public function preProcess() { parent::preProcess(); - $this->assign('selectedChild', 'reminder'); + $this->setSelectedChild('reminder'); $setTab = CRM_Utils_Request::retrieve('setTab', 'Int', $this, FALSE, 0); $mapping = CRM_Utils_Array::first(CRM_Core_BAO_ActionSchedule::getMappings([ diff --git a/CRM/Event/Form/ManageEvent/TabHeader.php b/CRM/Event/Form/ManageEvent/TabHeader.php index c966147e4f..d77440c1a0 100644 --- a/CRM/Event/Form/ManageEvent/TabHeader.php +++ b/CRM/Event/Form/ManageEvent/TabHeader.php @@ -45,8 +45,6 @@ class CRM_Event_Form_ManageEvent_TabHeader { * @throws \CRM_Core_Exception */ public static function build(&$form) { - $form->assign('selectedChild', CRM_Utils_Request::retrieve('selectedChild', 'Alphanumeric', $form)); - $tabs = $form->get('tabHeader'); if (!$tabs || empty($_GET['reset'])) { $tabs = self::process($form); diff --git a/CRM/Friend/Form/Event.php b/CRM/Friend/Form/Event.php index bf5b6cb518..2e68f80dc8 100644 --- a/CRM/Friend/Form/Event.php +++ b/CRM/Friend/Form/Event.php @@ -48,7 +48,7 @@ class CRM_Friend_Form_Event extends CRM_Event_Form_ManageEvent { public function preProcess() { parent::preProcess(); - $this->assign('selectedChild', 'friend'); + $this->setSelectedChild('friend'); } /** diff --git a/CRM/PCP/Form/Event.php b/CRM/PCP/Form/Event.php index da7802382b..f242036b3e 100644 --- a/CRM/PCP/Form/Event.php +++ b/CRM/PCP/Form/Event.php @@ -48,7 +48,7 @@ class CRM_PCP_Form_Event extends CRM_Event_Form_ManageEvent { public function preProcess() { parent::preProcess(); - $this->assign('selectedChild', 'pcp'); + $this->setSelectedChild('pcp'); } /** -- 2.25.1