From 3be2bae3c122188cfb7127754ce9a5ce3e694a8a Mon Sep 17 00:00:00 2001 From: colemanw Date: Fri, 9 Jun 2023 15:03:19 -0400 Subject: [PATCH] Prevent API errors when CiviEvent is disabled --- CRM/Event/BAO/Event.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/CRM/Event/BAO/Event.php b/CRM/Event/BAO/Event.php index 7adc12737b..70ae0fb86a 100644 --- a/CRM/Event/BAO/Event.php +++ b/CRM/Event/BAO/Event.php @@ -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; } /** -- 2.25.1