From c3d5497b160c973820a0e2c6bce0fe1fc0f268ba Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 17 Jan 2023 22:13:43 -0800 Subject: [PATCH] smarty-v2 - Avoid duplicate registrations --- mixin/smarty-v2@1/mixin.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/mixin/smarty-v2@1/mixin.php b/mixin/smarty-v2@1/mixin.php index 14e750e92d..137eb5ab47 100644 --- a/mixin/smarty-v2@1/mixin.php +++ b/mixin/smarty-v2@1/mixin.php @@ -18,15 +18,22 @@ return function ($mixInfo, $bootCache) { return; } - // Is it good or bad that this hasn't different static-guard-i-ness than the old 'hook_config' boilerplate? + $register = function() use ($dir) { + // This implementation is useful for older versions of CiviCRM. It can be replaced/updated going forward. + $smarty = CRM_Core_Smarty::singleton(); + if (!is_array($smarty->template_dir)) { + $this->template_dir = [$smarty->template_dir]; + } + if (!in_array($dir, $smarty->template_dir)) { + array_unshift($smarty->template_dir, $dir); + } + }; if ($mixInfo->isActive()) { - \Civi::dispatcher()->addListener('hook_civicrm_config', function () use ($dir) { - \CRM_Core_Smarty::singleton()->addTemplateDir($dir); - }); + \Civi::dispatcher()->addListener('hook_civicrm_config', $register); } elseif (CRM_Extension_System::singleton()->getManager()->extensionIsBeingInstalledOrEnabled($mixInfo->longName)) { - \CRM_Core_Smarty::singleton()->addTemplateDir($dir); + $register(); } }; -- 2.25.1