Skip to content

Commit

Permalink
Add check to ensure CiviCRM container is booted before invoking hooks (
Browse files Browse the repository at this point in the history
…#492)

- Introduced a conditional check to verify if the CiviCRM container is initialized.
- If the container is not booted, hooks will not be invoked, ensuring stability.
- This prevents potential errors related to uninitialized CiviCRM services.

Co-authored-by: Rafał Dziubak <[email protected]>
  • Loading branch information
rafaldziubak and dziubakrafal authored Aug 26, 2024
1 parent f58ed62 commit 1f8a906
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/SupportedEntities.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Drupal\civicrm_entity;

use Civi\Core\Container;
use Drupal\Component\Transliteration\TransliterationInterface;
use Drupal\Core\Language\LanguageInterface;

Expand Down Expand Up @@ -910,6 +911,10 @@ public static function getEntityTypeDaoClass($entity_type_id) {
public static function alterEntityInfo(array &$civicrm_entity_info) {
\Drupal::service('civicrm_entity.api')->civicrmInitialize();

if (!Container::isContainerBooted()) {
return FALSE;
}

$code_version = explode('.', \CRM_Utils_System::version());
if (version_compare($code_version[0] . '.' . $code_version[1], 4.5) >= 0) {
return \CRM_Utils_Hook::singleton()->invoke(['civicrm_entity_info'], $civicrm_entity_info,
Expand Down

0 comments on commit 1f8a906

Please sign in to comment.