From 282ca97f05c662c90a8c5c04682c367a95df29d8 Mon Sep 17 00:00:00 2001 From: Jaap Jansma Date: Mon, 29 Jan 2024 14:28:41 +0100 Subject: [PATCH] CiviCRM 5.69 Compatibility --- banking.civix.php | 11 ------- info.xml | 1 + mixin/smarty-v2@1.0.1.mixin.php | 51 +++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 11 deletions(-) create mode 100644 mixin/smarty-v2@1.0.1.mixin.php diff --git a/banking.civix.php b/banking.civix.php index 3872430b..74e149dc 100755 --- a/banking.civix.php +++ b/banking.civix.php @@ -98,18 +98,7 @@ function _banking_civix_civicrm_config(&$config = NULL) { } $configured = TRUE; - $template = CRM_Core_Smarty::singleton(); - $extRoot = __DIR__ . DIRECTORY_SEPARATOR; - $extDir = $extRoot . 'templates'; - - if (is_array($template->template_dir)) { - array_unshift($template->template_dir, $extDir); - } - else { - $template->template_dir = [$extDir, $template->template_dir]; - } - $include_path = $extRoot . PATH_SEPARATOR . get_include_path(); set_include_path($include_path); _banking_civix_mixin_polyfill(); diff --git a/info.xml b/info.xml index 644a706e..79ff7531 100755 --- a/info.xml +++ b/info.xml @@ -33,5 +33,6 @@ ang-php@1.0.0 menu-xml@1.0.0 mgd-php@1.0.0 + smarty-v2@1.0.1 diff --git a/mixin/smarty-v2@1.0.1.mixin.php b/mixin/smarty-v2@1.0.1.mixin.php new file mode 100644 index 00000000..5972dbdc --- /dev/null +++ b/mixin/smarty-v2@1.0.1.mixin.php @@ -0,0 +1,51 @@ +getPath('templates'); + if (!file_exists($dir)) { + return; + } + + $register = function() use ($dir) { + // This implementation has a theoretical edge-case bug on older versions of CiviCRM where a template could + // be registered more than once. + CRM_Core_Smarty::singleton()->addTemplateDir($dir); + }; + + // Let's figure out what environment we're in -- so that we know the best way to call $register(). + + if (!empty($GLOBALS['_CIVIX_MIXIN_POLYFILL'])) { + // Polyfill Loader (v<=5.45): We're already in the middle of firing `hook_config`. + if ($mixInfo->isActive()) { + $register(); + } + return; + } + + if (CRM_Extension_System::singleton()->getManager()->extensionIsBeingInstalledOrEnabled($mixInfo->longName)) { + // New Install, Standard Loader: The extension has just been enabled, and we're now setting it up. + // System has already booted. New templates may be needed for upcoming installation steps. + $register(); + return; + } + + // Typical Pageview, Standard Loader: Defer the actual registration for a moment -- to ensure that Smarty is online. + \Civi::dispatcher()->addListener('hook_civicrm_config', function() use ($mixInfo, $register) { + if ($mixInfo->isActive()) { + $register(); + } + }); + +};