From 73b67bf0526b316daae6abded58d64fddd112fcf Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Mon, 15 May 2023 15:53:09 +1200 Subject: [PATCH] Add getParticipantID to avoid non-php8-friendly path check This particular fail is due to the path being empy in the test environment - But it's wrong to check it as it is a crufty check for whether the search task is being used --- CRM/Event/Form/Participant.php | 51 ++++++++++++++++---------------- CRM/Event/Form/Task/Register.php | 17 +++++++++++ 2 files changed, 43 insertions(+), 25 deletions(-) diff --git a/CRM/Event/Form/Participant.php b/CRM/Event/Form/Participant.php index ea80920ca8..c4ce07fec9 100644 --- a/CRM/Event/Form/Participant.php +++ b/CRM/Event/Form/Participant.php @@ -25,6 +25,8 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment * Participant ID - use getParticipantID. * * @var int + * + * @deprecated unused */ public $_pId; @@ -69,6 +71,8 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment * The id of the participation that we are processing. * * @var int + * + * @internal use getParticipantID to access in a supported way. */ public $_id; @@ -198,9 +202,9 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment /** * Event id. * - * @internal - use getEventID - * * @var int + * + * @internal - use getEventID to access in a supported way */ public $_eventId; @@ -235,7 +239,8 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment * Get the selected Event ID. * * @api This function will not change in a minor release and is supported for - * use outside of core. + * use outside of core. This annotation / external support for properties + * is only given where there is specific test cover. * * @return int|null */ @@ -299,28 +304,15 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment $this->setPageTitle(ts('Event Registration')); } - // check the current path, if search based, then dont get participantID - // CRM-5792 - $path = CRM_Utils_System::currentPath(); - if ( - strpos($path, 'civicrm/contact/search') === 0 || - strpos($path, 'civicrm/group/search') === 0 - ) { - $this->_id = NULL; - } - else { - $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); - } - - if ($this->_id) { - $this->assign('participantId', $this->_id); + $this->assign('participantId', $this->getParticipantID()); + if ($this->getParticipantID()) { $this->_paymentId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_id, 'id', 'participant_id' ); $this->assign('hasPayment', $this->_paymentId); - $this->assign('componentId', $this->_id); + $this->assign('componentId', $this->getParticipantID()); $this->assign('component', 'event'); // CRM-12615 - Get payment information from the primary registration @@ -353,7 +345,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment $this->assign('single', $this->_single); - if (!$this->_id) { + if (!$this->getParticipantID()) { $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add'); } $this->assign('action', $this->_action); @@ -371,9 +363,6 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment return; } - // assign participant id to the template - $this->assign('participantId', $this->_id); - // when fee amount is included in form if (!empty($_POST['hidden_feeblock']) || !empty($_POST['send_receipt'])) { if ($this->_submitValues['event_id']) { @@ -1971,9 +1960,21 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment * Get id of participant being edited. * * @return int|null + * + * @api This function will not change in a minor release and is supported for + * use outside of core. This annotation / external support for properties + * is only given where there is specific test cover. + * + * No exception is thrown as abort is not TRUE. + * @noinspection PhpUnhandledExceptionInspection + * @noinspection PhpDocMissingThrowsInspection */ - protected function getParticipantID() { - return $this->_id ?? $this->_pId; + public function getParticipantID(): ?int { + if ($this->_id === NULL) { + $id = CRM_Utils_Request::retrieve('id', 'Positive', $this); + $this->_id = $id ? (int) $id : FALSE; + } + return $this->_id ?: NULL; } /** diff --git a/CRM/Event/Form/Task/Register.php b/CRM/Event/Form/Task/Register.php index 38df66c7ea..76a2860184 100644 --- a/CRM/Event/Form/Task/Register.php +++ b/CRM/Event/Form/Task/Register.php @@ -78,6 +78,23 @@ class CRM_Event_Form_Task_Register extends CRM_Event_Form_Participant { $this->assign('urlPathVar', "_qf_Participant_display=true&context=search"); } + /** + * Get id of participant being edited. + * + * This always returns null as it is the form to take action on search results. + * + * The parent class works on a single record & hence lik + * + * @api This function will not change in a minor release and is supported for + * use outside of core. This annotation / external support for properties + * is only given where there is specific test cover. + * + * @return null + */ + public function getParticipantID(): ?int { + return NULL; + } + /** * Process the form submission. * -- 2.25.1