Skip to content

Commit

Permalink
Add entity-types-php mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
colemanw committed Nov 10, 2022
1 parent 10f8344 commit 88b5352
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions mixin/entity-types-php@1/mixin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/**
* Auto-register entity declarations from `xml/schema/...*.entityType.php`.
*
* @mixinName entity-types-php
* @mixinVersion 1.0.0
* @since 5.57
*
* @param CRM_Extension_MixInfo $mixInfo
* On newer deployments, this will be an instance of MixInfo. On older deployments, Civix may polyfill with a work-a-like.
* @param \CRM_Extension_BootCache $bootCache
* On newer deployments, this will be an instance of MixInfo. On older deployments, Civix may polyfill with a work-a-like.
*/
return function ($mixInfo, $bootCache) {

/**
* @param \Civi\Core\Event\GenericHookEvent $e
* @see CRM_Utils_Hook::entityTypes()
*/
Civi::dispatcher()->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('xml/schema/CRM'))) {
return;
}

$files = (array) glob($mixInfo->getPath('xml/schema/CRM/*/*.entityType.php'));
foreach ($files as $file) {
$entity = include $file;
$e->entityTypes[$entity['class']] = $entity;
}
});

};

0 comments on commit 88b5352

Please sign in to comment.