diff --git a/mixin/entity-types-php@2.0.0.mixin.php b/mixin/entity-types-php@2.0.0.mixin.php new file mode 100644 index 0000000..54616e6 --- /dev/null +++ b/mixin/entity-types-php@2.0.0.mixin.php @@ -0,0 +1,40 @@ +addListener('hook_civicrm_entityTypes', function ($e) use ($mixInfo) { + // When deactivating on a polyfill/pre-mixin system, listeners may not cleanup automatically. + if (!$mixInfo->isActive() || !is_dir($mixInfo->getPath('schema'))) { + return; + } + + $files = (array) glob($mixInfo->getPath('schema/*.entityType.php')); + foreach ($files as $file) { + $entity = include $file; + $entity['module'] = $mixInfo->longName; + $e->entityTypes[$entity['name']] = $entity; + } + }); + +}; diff --git a/paymentprocessingcore.php b/paymentprocessingcore.php index c8e2bd5..254634c 100644 --- a/paymentprocessingcore.php +++ b/paymentprocessingcore.php @@ -32,6 +32,35 @@ function paymentprocessingcore_civicrm_enable(): void { _paymentprocessingcore_civix_civicrm_enable(); } +/** + * Implements hook_civicrm_entityTypes(). + * + * Directly registers entity types to work around a mixin timing issue on + * CiviCRM 5.75: the entity-types-php@2 mixin is only loaded for installed + * extensions, so during installation the mixin listener is absent and + * EntityRepository cannot find our entities. This direct hook ensures entity + * types are always registered. When both this and the mixin fire, the result + * is identical (same data, same keys). + * + * @see https://compucorp.atlassian.net/browse/CIVIPLMMSR-623 + * + * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_entityTypes + */ +function paymentprocessingcore_civicrm_entityTypes(&$entityTypes): void { + $schemaDir = __DIR__ . '/schema'; + if (!is_dir($schemaDir)) { + return; + } + $files = (array) glob($schemaDir . '/*.entityType.php'); + foreach ($files as $file) { + $entity = include $file; + if (is_array($entity) && !empty($entity['name'])) { + $entity['module'] = E::LONG_NAME; + $entityTypes[$entity['name']] = $entity; + } + } +} + /** * Implements hook_civicrm_container(). *