Fix theoretical regression
[civicrm-core.git] / CRM / Event / Form / Registration.php
index 0b0ee041a4a2d2a1ebbe773601e514aa980f6e7a..f6a19f5d864954ab74b9cc86f605c382fdf71958 100644 (file)
@@ -244,7 +244,7 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
         && CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()
         && !CRM_Core_Permission::check('add contributions of type ' . CRM_Contribute_PseudoConstant::financialType($this->_values['event']['financial_type_id']))
       ) {
-        CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
+        CRM_Core_Error::statusBounce(ts('You do not have permission to access this page.'));
       }
 
       $this->checkValidEvent($infoUrl);
@@ -692,7 +692,7 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
     }
 
     // add participant record
-    $participant = CRM_Event_Form_Registration::addParticipant($this, $contactID);
+    $participant = $this->addParticipant($this, $contactID);
     $this->_participantIDS[] = $participant->id;
 
     //setting register_by_id field and primaryContactId
@@ -778,10 +778,11 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
    * @return \CRM_Event_BAO_Participant
    * @throws \CiviCRM_API3_Exception
    */
-  public static function addParticipant(&$form, $contactID) {
+  protected function addParticipant(&$form, $contactID) {
     if (empty($form->_params)) {
       return NULL;
     }
+    // Note this used to be shared with the backoffice form & no longer is, some code may no longer be required.
     $params = $form->_params;
     $transaction = new CRM_Core_Transaction();
 
@@ -805,7 +806,7 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
       'status_id' => CRM_Utils_Array::value('participant_status',
         $params, 1
       ),
-      'role_id' => CRM_Utils_Array::value('participant_role_id', $params) ?: self::getDefaultRoleID(),
+      'role_id' => CRM_Utils_Array::value('participant_role_id', $params) ?: CRM_Event_BAO_Participant::getDefaultRoleID(),
       'register_date' => ($registerDate) ? $registerDate : date('YmdHis'),
       'source' => CRM_Utils_String::ellipsify(
         isset($params['participant_source']) ? CRM_Utils_Array::value('participant_source', $params) : CRM_Utils_Array::value('description', $params),
@@ -857,21 +858,6 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
     return $participant;
   }
 
-  /**
-   * Get the ID of the default (first) participant role
-   *
-   * @return int
-   * @throws \CiviCRM_API3_Exception
-   */
-  private static function getDefaultRoleID() {
-    return (int) civicrm_api3('OptionValue', 'getvalue', [
-      'return' => "value",
-      'option_group_id' => "participant_role",
-      'is_active' => 1,
-      'options' => ['limit' => 1, 'sort' => "is_default DESC"],
-    ]);
-  }
-
   /**
    * Calculate the total participant count as per params.
    *