From 7168793c03ef57c06bbfe45f5ff873ebb3657806 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Fri, 24 Feb 2023 20:36:50 +1300 Subject: [PATCH] Fix mixin --- CRM/Core/Smarty.php | 4 +++- mixin/smarty-v2@1/mixin.php | 13 ++++--------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/CRM/Core/Smarty.php b/CRM/Core/Smarty.php index 13db08c3b3..da5272d968 100644 --- a/CRM/Core/Smarty.php +++ b/CRM/Core/Smarty.php @@ -315,7 +315,9 @@ class CRM_Core_Smarty extends Smarty { return parent::addTemplateDir($template_dir, $key, $isConfig); } if (is_array($this->template_dir)) { - array_unshift($this->template_dir, $template_dir); + if (!in_array($template_dir, $this->template_dir)) { + array_unshift($this->template_dir, $template_dir); + } } else { $this->template_dir = [$template_dir, $this->template_dir]; diff --git a/mixin/smarty-v2@1/mixin.php b/mixin/smarty-v2@1/mixin.php index 0b371057cc..5972dbdc57 100644 --- a/mixin/smarty-v2@1/mixin.php +++ b/mixin/smarty-v2@1/mixin.php @@ -4,7 +4,7 @@ * Auto-register "templates/" folder. * * @mixinName smarty-v2 - * @mixinVersion 1.0.0 + * @mixinVersion 1.0.1 * @since 5.59 * * @param CRM_Extension_MixInfo $mixInfo @@ -19,14 +19,9 @@ return function ($mixInfo, $bootCache) { } $register = function() use ($dir) { - // This implementation is useful for older versions of CiviCRM. It can be replaced/updated going forward (v1.1+). - $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); - } + // 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(). -- 2.25.1