I have CiviCRM 5.56.1 installed via composer on a Drupal 9 application. In a custom module I use API v4 to manipulate records. For example, get membership types.
\Civi\Api4\MembershipType::get()->addWhere('name', 'My Membership')->execute();
The error that I get is the following:
Error: Class "CRM_Core_DAO" not found in /var/www/html/vendor/civicrm/civicrm-core/Civi/Api4/Utils/CoreUtil.php on line 101 #0 /var/www/html/vendor/civicrm/civicrm-core/Civi/Api4/Generic/DAOGetAction.php(156): Civi\Api4\Utils\CoreUtil::getOperators()
In my civicrm settings file I have made sure to add the correct $civicrm_root
variable. I have check the resulting include paths and the correct civicrm core path is included. CiviCRM in general works fine via the UI. The same command works when using the cv
CLI.
Any ideas why this happens when calling from within Drupal? It seems namespaced classes are found. In older related questions it is suggesting to use civicrm_initialize()
, but this function does not seem to exist anymore.