From b15bf7db02f8534a68de7f8c6dea48a0e83c70ec Mon Sep 17 00:00:00 2001
From: Jon Goldberg <jon@megaphonetech.com>
Date: Thu, 13 Apr 2023 16:31:57 -0400
Subject: [PATCH] civix upgrade v23.02.1

---
 cdntaxreceipts.civix.php        | 28 ++----------------
 cdntaxreceipts.php              | 11 -------
 info.xml                        |  3 +-
 mixin/smarty-v2@1.0.1.mixin.php | 51 +++++++++++++++++++++++++++++++++
 4 files changed, 56 insertions(+), 37 deletions(-)
 create mode 100644 mixin/smarty-v2@1.0.1.mixin.php

diff --git a/cdntaxreceipts.civix.php b/cdntaxreceipts.civix.php
index c8ed5d2..846686c 100644
--- a/cdntaxreceipts.civix.php
+++ b/cdntaxreceipts.civix.php
@@ -84,25 +84,14 @@ use CRM_Cdntaxreceipts_ExtensionUtil as E;
  *
  * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_config
  */
-function _cdntaxreceipts_civix_civicrm_config(&$config = NULL) {
+function _cdntaxreceipts_civix_civicrm_config($config = NULL) {
   static $configured = FALSE;
   if ($configured) {
     return;
   }
   $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);
   // Based on <compatibility>, this does not currently require mixin/polyfill.php.
@@ -144,8 +133,8 @@ function _cdntaxreceipts_civix_insert_navigation_menu(&$menu, $path, $item) {
   if (empty($path)) {
     $menu[] = [
       'attributes' => array_merge([
-        'label'      => CRM_Utils_Array::value('name', $item),
-        'active'     => 1,
+        'label' => $item['name'] ?? NULL,
+        'active' => 1,
       ], $item),
     ];
     return TRUE;
@@ -209,14 +198,3 @@ function _cdntaxreceipts_civix_fixNavigationMenuItems(&$nodes, &$maxNavID, $pare
     }
   }
 }
-
-/**
- * (Delegated) Implements hook_civicrm_entityTypes().
- *
- * Find any *.entityType.php files, merge their content, and return.
- *
- * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_entityTypes
- */
-function _cdntaxreceipts_civix_civicrm_entityTypes(&$entityTypes) {
-  $entityTypes = array_merge($entityTypes, []);
-}
diff --git a/cdntaxreceipts.php b/cdntaxreceipts.php
index eaa0ba5..cca67cd 100644
--- a/cdntaxreceipts.php
+++ b/cdntaxreceipts.php
@@ -167,17 +167,6 @@ function cdntaxreceipts_civicrm_enable() {
   return _cdntaxreceipts_civix_civicrm_enable();
 }
 
-/**
- * Implements hook_civicrm_entityTypes().
- *
- * Declare entity types provided by this module.
- *
- * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_entityTypes
- */
-function cdntaxreceipts_civicrm_entityTypes(&$entityTypes) {
-  _cdntaxreceipts_civix_civicrm_entityTypes($entityTypes);
-}
-
 /**
  * Implements hook_civicrm_navigationMenu().
  *
diff --git a/info.xml b/info.xml
index 5f8e601..a5b4580 100644
--- a/info.xml
+++ b/info.xml
@@ -28,11 +28,12 @@
   </comments>
   <civix>
     <namespace>CRM/Cdntaxreceipts</namespace>
-    <format>22.12.1</format>
+    <format>23.02.1</format>
   </civix>
   <mixins>
     <mixin>menu-xml@1.0.0</mixin>
     <mixin>mgd-php@1.0.0</mixin>
+    <mixin>smarty-v2@1.0.1</mixin>
   </mixins>
   <classloader>
     <psr0 prefix="CRM_" path="."/>
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 0000000..5972dbd
--- /dev/null
+++ b/mixin/smarty-v2@1.0.1.mixin.php
@@ -0,0 +1,51 @@
+<?php
+
+/**
+ * Auto-register "templates/" folder.
+ *
+ * @mixinName smarty-v2
+ * @mixinVersion 1.0.1
+ * @since 5.59
+ *
+ * @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) {
+  $dir = $mixInfo->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();
+    }
+  });
+
+};
-- 
GitLab