From 3bc4f2243716d096870e062f24d5eac4d0f8de83 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Tue, 21 Apr 2026 11:01:41 +0100 Subject: [PATCH] CIVIPLMMSR-623: Fix entity type registration on CiviCRM 5.75 The extension fails to enable on CiviCRM 5.75 with a TypeError because entity types are not registered during installation. The MixinScanner only processes installed extensions, so the entity-types-php@2 mixin listener is never loaded for this extension during its own install. - Bundle entity-types-php@2.0.0.mixin.php (copied from Stripe, matching the standard CiviCRM pattern for extensions with custom entities) - Add direct hook_civicrm_entityTypes implementation as a fallback that registers entity types from schema/*.entityType.php regardless of mixin timing. When both fire, the result is identical (same keys). On CiviCRM 6.4+ this is a harmless no-op. --- mixin/entity-types-php@2.0.0.mixin.php | 40 ++++++++++++++++++++++++++ paymentprocessingcore.php | 29 +++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 mixin/entity-types-php@2.0.0.mixin.php 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(). *