Skip to content

Commit 8bc90f6

Browse files
author
Chris Garaffa
committed
Civix upgrade for Smarty compatibility
1 parent c4a7c69 commit 8bc90f6

File tree

5 files changed

+142
-396
lines changed

5 files changed

+142
-396
lines changed

info.xml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,21 @@
1111
<urls>
1212
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
1313
</urls>
14-
<releaseDate>2019-09-05</releaseDate>
15-
<version>1.0</version>
14+
<releaseDate>2024-12-24</releaseDate>
15+
<version>1.1</version>
1616
<compatibility>
17-
<ver>5.0</ver>
17+
<ver>5.45</ver>
1818
</compatibility>
1919
<civix>
2020
<namespace>CRM/Otheramounts</namespace>
21+
<format>24.09.1</format>
2122
</civix>
23+
<mixins>
24+
<mixin>[email protected]</mixin>
25+
<mixin>[email protected]</mixin>
26+
<mixin>[email protected]</mixin>
27+
</mixins>
28+
<classloader>
29+
<psr4 prefix="Civi\" path="Civi"/>
30+
</classloader>
2231
</extension>

mixin/[email protected]

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
/**
4+
* Auto-register entity declarations from `schema/*.entityType.php`.
5+
*
6+
* @mixinName entity-types-php
7+
* @mixinVersion 2.0.0
8+
* @since 5.73
9+
*
10+
* Changelog:
11+
* - v2.0 scans /schema directory instead of /xml/schema/*
12+
* - v2.0 supports only one entity per file
13+
* - v2.0 adds 'module' key to each entity
14+
*
15+
* @param CRM_Extension_MixInfo $mixInfo
16+
* On newer deployments, this will be an instance of MixInfo. On older deployments, Civix may polyfill with a work-a-like.
17+
* @param \CRM_Extension_BootCache $bootCache
18+
* On newer deployments, this will be an instance of BootCache. On older deployments, Civix may polyfill with a work-a-like.
19+
*/
20+
return function ($mixInfo, $bootCache) {
21+
22+
/**
23+
* @param \Civi\Core\Event\GenericHookEvent $e
24+
* @see CRM_Utils_Hook::entityTypes()
25+
*/
26+
Civi::dispatcher()->addListener('hook_civicrm_entityTypes', function ($e) use ($mixInfo) {
27+
// When deactivating on a polyfill/pre-mixin system, listeners may not cleanup automatically.
28+
if (!$mixInfo->isActive() || !is_dir($mixInfo->getPath('schema'))) {
29+
return;
30+
}
31+
32+
$files = (array) glob($mixInfo->getPath('schema/*.entityType.php'));
33+
foreach ($files as $file) {
34+
$entity = include $file;
35+
$entity['module'] = $mixInfo->longName;
36+
$e->entityTypes[$entity['name']] = $entity;
37+
}
38+
});
39+
40+
};

mixin/[email protected]

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
/**
4+
* Auto-register "templates/" folder.
5+
*
6+
* @mixinName smarty-v2
7+
* @mixinVersion 1.0.3
8+
* @since 5.59
9+
*
10+
* @deprecated - it turns out that the mixin is not version specific so the 'smarty'
11+
* mixin is preferred over smarty-v2 (they are the same but not having the version
12+
* in the name is less misleading.)
13+
*
14+
* @param CRM_Extension_MixInfo $mixInfo
15+
* On newer deployments, this will be an instance of MixInfo. On older deployments, Civix may polyfill with a work-a-like.
16+
* @param \CRM_Extension_BootCache $bootCache
17+
* On newer deployments, this will be an instance of MixInfo. On older deployments, Civix may polyfill with a work-a-like.
18+
*/
19+
return function ($mixInfo, $bootCache) {
20+
$dir = $mixInfo->getPath('templates');
21+
if (!file_exists($dir)) {
22+
return;
23+
}
24+
25+
$register = function($newDirs) {
26+
$smarty = CRM_Core_Smarty::singleton();
27+
$v2 = isset($smarty->_version) && version_compare($smarty->_version, 3, '<');
28+
$templateDirs = (array) ($v2 ? $smarty->template_dir : $smarty->getTemplateDir());
29+
$templateDirs = array_merge($newDirs, $templateDirs);
30+
$templateDirs = array_unique(array_map(function($v) {
31+
$v = str_replace(DIRECTORY_SEPARATOR, '/', $v);
32+
$v = rtrim($v, '/') . '/';
33+
return $v;
34+
}, $templateDirs));
35+
if ($v2) {
36+
$smarty->template_dir = $templateDirs;
37+
}
38+
else {
39+
$smarty->setTemplateDir($templateDirs);
40+
}
41+
};
42+
43+
// Let's figure out what environment we're in -- so that we know the best way to call $register().
44+
45+
if (!empty($GLOBALS['_CIVIX_MIXIN_POLYFILL'])) {
46+
// Polyfill Loader (v<=5.45): We're already in the middle of firing `hook_config`.
47+
if ($mixInfo->isActive()) {
48+
$register([$dir]);
49+
}
50+
return;
51+
}
52+
53+
if (CRM_Extension_System::singleton()->getManager()->extensionIsBeingInstalledOrEnabled($mixInfo->longName)) {
54+
// New Install, Standard Loader: The extension has just been enabled, and we're now setting it up.
55+
// System has already booted. New templates may be needed for upcoming installation steps.
56+
$register([$dir]);
57+
return;
58+
}
59+
60+
// Typical Pageview, Standard Loader: Defer the actual registration for a moment -- to ensure that Smarty is online.
61+
// We need to bundle-up all dirs -- Smarty 3/4/5 is inefficient with processing repeated calls to `getTemplateDir()`+`setTemplateDir()`
62+
if (!isset(Civi::$statics[__FILE__]['event'])) {
63+
Civi::$statics[__FILE__]['event'] = 'civi.smarty-v2.addPaths.' . md5(__FILE__);
64+
Civi::dispatcher()->addListener('hook_civicrm_config', function() use ($register) {
65+
$dirs = [];
66+
$event = \Civi\Core\Event\GenericHookEvent::create(['dirs' => &$dirs]);
67+
Civi::dispatcher()->dispatch(Civi::$statics[__FILE__]['event'], $event);
68+
$register($dirs);
69+
});
70+
}
71+
72+
Civi::dispatcher()->addListener(Civi::$statics[__FILE__]['event'], function($event) use ($mixInfo, $dir) {
73+
if ($mixInfo->isActive()) {
74+
array_unshift($event->dirs, $dir);
75+
}
76+
});
77+
78+
};

0 commit comments

Comments
 (0)