Prevent API errors when CiviEvent is disabled
authorcolemanw <coleman@civicrm.org>
Fri, 9 Jun 2023 19:03:19 +0000 (15:03 -0400)
committercolemanw <coleman@civicrm.org>
Fri, 9 Jun 2023 19:03:19 +0000 (15:03 -0400)
CRM/Event/BAO/Event.php

index 7adc12737b3af706722cfa649bb6a586a7a0e78f..70ae0fb86a476a7c140e02c16f6905d021961fe6 100644 (file)
@@ -315,19 +315,22 @@ WHERE  ( civicrm_event.is_template IS NULL OR civicrm_event.is_template = 0 )";
   }
 
   /**
-   * Returns an array of event pages [id => title]
+   * Callback for the experimental `event_show_payment_on_confirm` setting.
+   * Should be removed when that setting gets retired.
    * @return array
-   * @throws \API_Exception
-   * @throws \Civi\API\Exception\UnauthorizedException
    */
   public static function getEventsForSelect2() {
-    return ['all' => ts('- all -')] +
-      \Civi\Api4\Event::get(FALSE)
+    $options = ['all' => ts('- all -')];
+    // Check that CiviEvent is enabled before calling the api
+    if (class_exists('\Civi\Api4\Event')) {
+      $options += \Civi\Api4\Event::get(FALSE)
         ->addSelect('id', 'title')
         ->addWhere('is_active', '=', TRUE)
         ->execute()
         ->indexBy('id')
         ->column('title');
+    }
+    return $options;
   }
 
   /**