diff --git a/info.xml b/info.xml
index a53689d..1d4f18d 100755
--- a/info.xml
+++ b/info.xml
@@ -18,14 +18,19 @@
1.2
stable
- 4.4
- 4.5
- 4.6
- 4.7
- 5.7
+ 5.27
-
+
CRM/Lineitemreport
+ 25.01.1
+
+ mgd-php@1.0.0
+ smarty-v2@1.0.3
+
+
+
+
+
diff --git a/lineitemreport.civix.php b/lineitemreport.civix.php
index fe3e543..25b0962 100755
--- a/lineitemreport.civix.php
+++ b/lineitemreport.civix.php
@@ -3,259 +3,160 @@
// AUTO-GENERATED FILE -- Civix may overwrite any changes made to this file
/**
- * (Delegated) Implementation of hook_civicrm_config
- *
- * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_config
+ * The ExtensionUtil class provides small stubs for accessing resources of this
+ * extension.
*/
-function _lineitemreport_civix_civicrm_config(&$config = NULL) {
- static $configured = FALSE;
- if ($configured) return;
- $configured = TRUE;
-
- $template =& CRM_Core_Smarty::singleton();
-
- $extRoot = dirname( __FILE__ ) . DIRECTORY_SEPARATOR;
- $extDir = $extRoot . 'templates';
-
- if ( is_array( $template->template_dir ) ) {
- array_unshift( $template->template_dir, $extDir );
- } else {
- $template->template_dir = array( $extDir, $template->template_dir );
+class CRM_Lineitemreport_ExtensionUtil {
+ const SHORT_NAME = 'lineitemreport';
+ const LONG_NAME = 'com.skvare.lineitemreport';
+ const CLASS_PREFIX = 'CRM_Lineitemreport';
+
+ /**
+ * Translate a string using the extension's domain.
+ *
+ * If the extension doesn't have a specific translation
+ * for the string, fallback to the default translations.
+ *
+ * @param string $text
+ * Canonical message text (generally en_US).
+ * @param array $params
+ * @return string
+ * Translated text.
+ * @see ts
+ */
+ public static function ts($text, $params = []): string {
+ if (!array_key_exists('domain', $params)) {
+ $params['domain'] = [self::LONG_NAME, NULL];
+ }
+ return ts($text, $params);
}
- $include_path = $extRoot . PATH_SEPARATOR . get_include_path( );
- set_include_path( $include_path );
-}
-
-/**
- * (Delegated) Implementation of hook_civicrm_xmlMenu
- *
- * @param $files array(string)
- * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_xmlMenu
- */
-function _lineitemreport_civix_civicrm_xmlMenu(&$files) {
- foreach (_lineitemreport_civix_glob(__DIR__ . '/xml/Menu/*.xml') as $file) {
- $files[] = $file;
+ /**
+ * Get the URL of a resource file (in this extension).
+ *
+ * @param string|NULL $file
+ * Ex: NULL.
+ * Ex: 'css/foo.css'.
+ * @return string
+ * Ex: 'http://example.org/sites/default/ext/org.example.foo'.
+ * Ex: 'http://example.org/sites/default/ext/org.example.foo/css/foo.css'.
+ */
+ public static function url($file = NULL): string {
+ if ($file === NULL) {
+ return rtrim(CRM_Core_Resources::singleton()->getUrl(self::LONG_NAME), '/');
+ }
+ return CRM_Core_Resources::singleton()->getUrl(self::LONG_NAME, $file);
}
-}
-/**
- * Implementation of hook_civicrm_install
- *
- * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_install
- */
-function _lineitemreport_civix_civicrm_install() {
- _lineitemreport_civix_civicrm_config();
- if ($upgrader = _lineitemreport_civix_upgrader()) {
- $upgrader->onInstall();
+ /**
+ * Get the path of a resource file (in this extension).
+ *
+ * @param string|NULL $file
+ * Ex: NULL.
+ * Ex: 'css/foo.css'.
+ * @return string
+ * Ex: '/var/www/example.org/sites/default/ext/org.example.foo'.
+ * Ex: '/var/www/example.org/sites/default/ext/org.example.foo/css/foo.css'.
+ */
+ public static function path($file = NULL) {
+ // return CRM_Core_Resources::singleton()->getPath(self::LONG_NAME, $file);
+ return __DIR__ . ($file === NULL ? '' : (DIRECTORY_SEPARATOR . $file));
}
-}
-/**
- * Implementation of hook_civicrm_uninstall
- *
- * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_uninstall
- */
-function _lineitemreport_civix_civicrm_uninstall() {
- _lineitemreport_civix_civicrm_config();
- if ($upgrader = _lineitemreport_civix_upgrader()) {
- $upgrader->onUninstall();
+ /**
+ * Get the name of a class within this extension.
+ *
+ * @param string $suffix
+ * Ex: 'Page_HelloWorld' or 'Page\\HelloWorld'.
+ * @return string
+ * Ex: 'CRM_Foo_Page_HelloWorld'.
+ */
+ public static function findClass($suffix) {
+ return self::CLASS_PREFIX . '_' . str_replace('\\', '_', $suffix);
}
-}
-/**
- * (Delegated) Implementation of hook_civicrm_enable
- *
- * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_enable
- */
-function _lineitemreport_civix_civicrm_enable() {
- _lineitemreport_civix_civicrm_config();
- if ($upgrader = _lineitemreport_civix_upgrader()) {
- if (is_callable(array($upgrader, 'onEnable'))) {
- $upgrader->onEnable();
- }
- }
}
-/**
- * (Delegated) Implementation of hook_civicrm_disable
- *
- * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_disable
- * @return mixed
- */
-function _lineitemreport_civix_civicrm_disable() {
- _lineitemreport_civix_civicrm_config();
- if ($upgrader = _lineitemreport_civix_upgrader()) {
- if (is_callable(array($upgrader, 'onDisable'))) {
- $upgrader->onDisable();
- }
- }
-}
+use CRM_Lineitemreport_ExtensionUtil as E;
-/**
- * (Delegated) Implementation of hook_civicrm_upgrade
- *
- * @param $op string, the type of operation being performed; 'check' or 'enqueue'
- * @param $queue CRM_Queue_Queue, (for 'enqueue') the modifiable list of pending up upgrade tasks
- *
- * @return mixed based on op. for 'check', returns array(boolean) (TRUE if upgrades are pending)
- * for 'enqueue', returns void
- *
- * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_upgrade
- */
-function _lineitemreport_civix_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) {
- if ($upgrader = _lineitemreport_civix_upgrader()) {
- return $upgrader->onUpgrade($op, $queue);
- }
-}
-
-/**
- * @return CRM_Lineitemreport_Upgrader
- */
-function _lineitemreport_civix_upgrader() {
- if (!file_exists(__DIR__.'/CRM/Lineitemreport/Upgrader.php')) {
- return NULL;
- } else {
- return CRM_Lineitemreport_Upgrader_Base::instance();
+function _lineitemreport_civix_mixin_polyfill() {
+ if (!class_exists('CRM_Extension_MixInfo')) {
+ $polyfill = __DIR__ . '/mixin/polyfill.php';
+ (require $polyfill)(E::LONG_NAME, E::SHORT_NAME, E::path());
}
}
/**
- * Search directory tree for files which match a glob pattern
- *
- * Note: Dot-directories (like "..", ".git", or ".svn") will be ignored.
- * Note: In Civi 4.3+, delegate to CRM_Utils_File::findFiles()
+ * (Delegated) Implements hook_civicrm_config().
*
- * @param $dir string, base dir
- * @param $pattern string, glob pattern, eg "*.txt"
- * @return array(string)
+ * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_config
*/
-function _lineitemreport_civix_find_files($dir, $pattern) {
- if (is_callable(array('CRM_Utils_File', 'findFiles'))) {
- return CRM_Utils_File::findFiles($dir, $pattern);
+function _lineitemreport_civix_civicrm_config($config = NULL) {
+ static $configured = FALSE;
+ if ($configured) {
+ return;
}
+ $configured = TRUE;
- $todos = array($dir);
- $result = array();
- while (!empty($todos)) {
- $subdir = array_shift($todos);
- foreach (_lineitemreport_civix_glob("$subdir/$pattern") as $match) {
- if (!is_dir($match)) {
- $result[] = $match;
- }
- }
- if ($dh = opendir($subdir)) {
- while (FALSE !== ($entry = readdir($dh))) {
- $path = $subdir . DIRECTORY_SEPARATOR . $entry;
- if ($entry[0] == '.') {
- } elseif (is_dir($path)) {
- $todos[] = $path;
- }
- }
- closedir($dh);
- }
- }
- return $result;
-}
-/**
- * (Delegated) Implementation of hook_civicrm_managed
- *
- * Find any *.mgd.php files, merge their content, and return.
- *
- * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_managed
- */
-function _lineitemreport_civix_civicrm_managed(&$entities) {
- $mgdFiles = _lineitemreport_civix_find_files(__DIR__, '*.mgd.php');
- foreach ($mgdFiles as $file) {
- $es = include $file;
- foreach ($es as $e) {
- if (empty($e['module'])) {
- $e['module'] = 'com.skvare.lineitemreport';
- }
- $entities[] = $e;
- }
- }
+ $extRoot = __DIR__ . DIRECTORY_SEPARATOR;
+ $include_path = $extRoot . PATH_SEPARATOR . get_include_path();
+ set_include_path($include_path);
+ _lineitemreport_civix_mixin_polyfill();
}
/**
- * (Delegated) Implementation of hook_civicrm_caseTypes
- *
- * Find any and return any files matching "xml/case/*.xml"
- *
- * Note: This hook only runs in CiviCRM 4.4+.
+ * Implements hook_civicrm_install().
*
- * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_caseTypes
+ * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_install
*/
-function _lineitemreport_civix_civicrm_caseTypes(&$caseTypes) {
- if (!is_dir(__DIR__ . '/xml/case')) {
- return;
- }
-
- foreach (_lineitemreport_civix_glob(__DIR__ . '/xml/case/*.xml') as $file) {
- $name = preg_replace('/\.xml$/', '', basename($file));
- if ($name != CRM_Case_XMLProcessor::mungeCaseType($name)) {
- $errorMessage = sprintf("Case-type file name is malformed (%s vs %s)", $name, CRM_Case_XMLProcessor::mungeCaseType($name));
- CRM_Core_Error::fatal($errorMessage);
- // throw new CRM_Core_Exception($errorMessage);
- }
- $caseTypes[$name] = array(
- 'module' => 'com.skvare.lineitemreport',
- 'name' => $name,
- 'file' => $file,
- );
- }
+function _lineitemreport_civix_civicrm_install() {
+ _lineitemreport_civix_civicrm_config();
+ _lineitemreport_civix_mixin_polyfill();
}
/**
- * Glob wrapper which is guaranteed to return an array.
- *
- * The documentation for glob() says, "On some systems it is impossible to
- * distinguish between empty match and an error." Anecdotally, the return
- * result for an empty match is sometimes array() and sometimes FALSE.
- * This wrapper provides consistency.
+ * (Delegated) Implements hook_civicrm_enable().
*
- * @link http://php.net/glob
- * @param string $pattern
- * @return array, possibly empty
+ * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_enable
*/
-function _lineitemreport_civix_glob($pattern) {
- $result = glob($pattern);
- return is_array($result) ? $result : array();
+function _lineitemreport_civix_civicrm_enable(): void {
+ _lineitemreport_civix_civicrm_config();
+ _lineitemreport_civix_mixin_polyfill();
}
/**
- * Inserts a navigation menu item at a given place in the hierarchy
+ * Inserts a navigation menu item at a given place in the hierarchy.
*
- * $menu - menu hierarchy
- * $path - path where insertion should happen (ie. Administer/System Settings)
- * $item - menu you need to insert (parent/child attributes will be filled for you)
- * $parentId - used internally to recurse in the menu structure
+ * @param array $menu - menu hierarchy
+ * @param string $path - path to parent of this item, e.g. 'my_extension/submenu'
+ * 'Mailing', or 'Administer/System Settings'
+ * @param array $item - the item to insert (parent/child attributes will be
+ * filled for you)
+ *
+ * @return bool
*/
-function _lineitemreport_civix_insert_navigation_menu(&$menu, $path, $item, $parentId = NULL) {
- static $navId;
-
+function _lineitemreport_civix_insert_navigation_menu(&$menu, $path, $item) {
// If we are done going down the path, insert menu
if (empty($path)) {
- if (!$navId) $navId = CRM_Core_DAO::singleValueQuery("SELECT max(id) FROM civicrm_navigation");
- $navId ++;
- $menu[$navId] = array (
- 'attributes' => array_merge($item, array(
- 'label' => CRM_Utils_Array::value('name', $item),
- 'active' => 1,
- 'parentID' => $parentId,
- 'navID' => $navId,
- ))
- );
- return true;
- } else {
+ $menu[] = [
+ 'attributes' => array_merge([
+ 'label' => $item['name'] ?? NULL,
+ 'active' => 1,
+ ], $item),
+ ];
+ return TRUE;
+ }
+ else {
// Find an recurse into the next level down
- $found = false;
+ $found = FALSE;
$path = explode('/', $path);
$first = array_shift($path);
foreach ($menu as $key => &$entry) {
if ($entry['attributes']['name'] == $first) {
- if (!$entry['child']) $entry['child'] = array();
- $found = _lineitemreport_civix_insert_navigation_menu($entry['child'], implode('/', $path), $item, $key);
+ if (!isset($entry['child'])) {
+ $entry['child'] = [];
+ }
+ $found = _lineitemreport_civix_insert_navigation_menu($entry['child'], implode('/', $path), $item);
}
}
return $found;
@@ -263,17 +164,44 @@ function _lineitemreport_civix_insert_navigation_menu(&$menu, $path, $item, $par
}
/**
- * (Delegated) Implementation of hook_civicrm_alterSettingsFolders
- *
- * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_alterSettingsFolders
+ * (Delegated) Implements hook_civicrm_navigationMenu().
*/
-function _lineitemreport_civix_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) {
- static $configured = FALSE;
- if ($configured) return;
- $configured = TRUE;
+function _lineitemreport_civix_navigationMenu(&$nodes) {
+ if (!is_callable(['CRM_Core_BAO_Navigation', 'fixNavigationMenu'])) {
+ _lineitemreport_civix_fixNavigationMenu($nodes);
+ }
+}
- $settingsDir = __DIR__ . DIRECTORY_SEPARATOR . 'settings';
- if(is_dir($settingsDir) && !in_array($settingsDir, $metaDataFolders)) {
- $metaDataFolders[] = $settingsDir;
+/**
+ * Given a navigation menu, generate navIDs for any items which are
+ * missing them.
+ */
+function _lineitemreport_civix_fixNavigationMenu(&$nodes) {
+ $maxNavID = 1;
+ array_walk_recursive($nodes, function($item, $key) use (&$maxNavID) {
+ if ($key === 'navID') {
+ $maxNavID = max($maxNavID, $item);
+ }
+ });
+ _lineitemreport_civix_fixNavigationMenuItems($nodes, $maxNavID, NULL);
+}
+
+function _lineitemreport_civix_fixNavigationMenuItems(&$nodes, &$maxNavID, $parentID) {
+ $origKeys = array_keys($nodes);
+ foreach ($origKeys as $origKey) {
+ if (!isset($nodes[$origKey]['attributes']['parentID']) && $parentID !== NULL) {
+ $nodes[$origKey]['attributes']['parentID'] = $parentID;
+ }
+ // If no navID, then assign navID and fix key.
+ if (!isset($nodes[$origKey]['attributes']['navID'])) {
+ $newKey = ++$maxNavID;
+ $nodes[$origKey]['attributes']['navID'] = $newKey;
+ $nodes[$newKey] = $nodes[$origKey];
+ unset($nodes[$origKey]);
+ $origKey = $newKey;
+ }
+ if (isset($nodes[$origKey]['child']) && is_array($nodes[$origKey]['child'])) {
+ _lineitemreport_civix_fixNavigationMenuItems($nodes[$origKey]['child'], $maxNavID, $nodes[$origKey]['attributes']['navID']);
+ }
}
}
diff --git a/lineitemreport.php b/lineitemreport.php
index f8c0a98..af93612 100755
--- a/lineitemreport.php
+++ b/lineitemreport.php
@@ -11,17 +11,6 @@ function lineitemreport_civicrm_config(&$config) {
_lineitemreport_civix_civicrm_config($config);
}
-/**
- * Implementation of hook_civicrm_xmlMenu
- *
- * @param $files array(string)
- *
- * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_xmlMenu
- */
-function lineitemreport_civicrm_xmlMenu(&$files) {
- _lineitemreport_civix_civicrm_xmlMenu($files);
-}
-
/**
* Implementation of hook_civicrm_install
*
@@ -31,15 +20,6 @@ function lineitemreport_civicrm_install() {
return _lineitemreport_civix_civicrm_install();
}
-/**
- * Implementation of hook_civicrm_uninstall
- *
- * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_uninstall
- */
-function lineitemreport_civicrm_uninstall() {
- return _lineitemreport_civix_civicrm_uninstall();
-}
-
/**
* Implementation of hook_civicrm_enable
*
@@ -48,61 +28,3 @@ function lineitemreport_civicrm_uninstall() {
function lineitemreport_civicrm_enable() {
return _lineitemreport_civix_civicrm_enable();
}
-
-/**
- * Implementation of hook_civicrm_disable
- *
- * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_disable
- */
-function lineitemreport_civicrm_disable() {
- return _lineitemreport_civix_civicrm_disable();
-}
-
-/**
- * Implementation of hook_civicrm_upgrade
- *
- * @param $op string, the type of operation being performed; 'check' or 'enqueue'
- * @param $queue CRM_Queue_Queue, (for 'enqueue') the modifiable list of pending up upgrade tasks
- *
- * @return mixed based on op. for 'check', returns array(boolean) (TRUE if upgrades are pending)
- * for 'enqueue', returns void
- *
- * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_upgrade
- */
-function lineitemreport_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) {
- return _lineitemreport_civix_civicrm_upgrade($op, $queue);
-}
-
-/**
- * Implementation of hook_civicrm_managed
- *
- * Generate a list of entities to create/deactivate/delete when this module
- * is installed, disabled, uninstalled.
- *
- * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_managed
- */
-function lineitemreport_civicrm_managed(&$entities) {
- return _lineitemreport_civix_civicrm_managed($entities);
-}
-
-/**
- * Implementation of hook_civicrm_caseTypes
- *
- * Generate a list of case-types
- *
- * Note: This hook only runs in CiviCRM 4.4+.
- *
- * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_caseTypes
- */
-function lineitemreport_civicrm_caseTypes(&$caseTypes) {
- return _lineitemreport_civix_civicrm_caseTypes($caseTypes);
-}
-
-/**
- * Implementation of hook_civicrm_alterSettingsFolders
- *
- * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_alterSettingsFolders
- */
-function lineitemreport_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) {
- return _lineitemreport_civix_civicrm_alterSettingsFolders($metaDataFolders);
-}
diff --git a/mixin/mgd-php@1.0.0.mixin.php b/mixin/mgd-php@1.0.0.mixin.php
new file mode 100644
index 0000000..39d45b1
--- /dev/null
+++ b/mixin/mgd-php@1.0.0.mixin.php
@@ -0,0 +1,42 @@
+addListener('hook_civicrm_managed', function ($event) use ($mixInfo) {
+ // When deactivating on a polyfill/pre-mixin system, listeners may not cleanup automatically.
+ if (!$mixInfo->isActive()) {
+ return;
+ }
+
+ $mgdFiles = CRM_Utils_File::findFiles($mixInfo->getPath(), '*.mgd.php');
+ sort($mgdFiles);
+ foreach ($mgdFiles as $file) {
+ $es = include $file;
+ foreach ($es as $e) {
+ if (empty($e['module'])) {
+ $e['module'] = $mixInfo->longName;
+ }
+ if (empty($e['params']['version'])) {
+ $e['params']['version'] = '3';
+ }
+ $event->entities[] = $e;
+ }
+ }
+ });
+
+};
diff --git a/mixin/polyfill.php b/mixin/polyfill.php
new file mode 100644
index 0000000..be40364
--- /dev/null
+++ b/mixin/polyfill.php
@@ -0,0 +1,101 @@
+')) {
+ $mixinVers[$name] = $ver;
+ }
+ }
+ $mixins = [];
+ foreach ($mixinVers as $name => $ver) {
+ $mixins[] = "$name@$ver";
+ }
+
+ // Imitate CRM_Extension_MixInfo.
+ $mixInfo = new class() {
+
+ /**
+ * @var string
+ */
+ public $longName;
+
+ /**
+ * @var string
+ */
+ public $shortName;
+
+ public $_basePath;
+
+ public function getPath($file = NULL) {
+ return $this->_basePath . ($file === NULL ? '' : (DIRECTORY_SEPARATOR . $file));
+ }
+
+ public function isActive() {
+ return \CRM_Extension_System::singleton()->getMapper()->isActiveModule($this->shortName);
+ }
+
+ };
+ $mixInfo->longName = $longName;
+ $mixInfo->shortName = $shortName;
+ $mixInfo->_basePath = $basePath;
+
+ // Imitate CRM_Extension_BootCache.
+ $bootCache = new class() {
+
+ public function define($name, $callback) {
+ $envId = \CRM_Core_Config_Runtime::getId();
+ $oldExtCachePath = \Civi::paths()->getPath("[civicrm.compile]/CachedExtLoader.{$envId}.php");
+ $stat = stat($oldExtCachePath);
+ $file = Civi::paths()->getPath('[civicrm.compile]/CachedMixin.' . md5($name . ($stat['mtime'] ?? 0)) . '.php');
+ if (file_exists($file)) {
+ return include $file;
+ }
+ else {
+ $data = $callback();
+ file_put_contents($file, '<' . "?php\nreturn " . var_export($data, TRUE) . ';');
+ return $data;
+ }
+ }
+
+ };
+
+ // Imitate CRM_Extension_MixinLoader::run()
+ // Parse all live mixins before trying to scan any classes.
+ global $_CIVIX_MIXIN_POLYFILL;
+ foreach ($mixins as $mixin) {
+ // If the exact same mixin is defined by multiple exts, just use the first one.
+ if (!isset($_CIVIX_MIXIN_POLYFILL[$mixin])) {
+ $_CIVIX_MIXIN_POLYFILL[$mixin] = include_once $basePath . '/mixin/' . $mixin . '.mixin.php';
+ }
+ }
+ foreach ($mixins as $mixin) {
+ // If there's trickery about installs/uninstalls/resets, then we may need to register a second time.
+ if (!isset(\Civi::$statics[$longName][$mixin])) {
+ \Civi::$statics[$longName][$mixin] = 1;
+ $func = $_CIVIX_MIXIN_POLYFILL[$mixin];
+ $func($mixInfo, $bootCache);
+ }
+ }
+};
diff --git a/mixin/smarty-v2@1.0.3.mixin.php b/mixin/smarty-v2@1.0.3.mixin.php
new file mode 100644
index 0000000..f8718c8
--- /dev/null
+++ b/mixin/smarty-v2@1.0.3.mixin.php
@@ -0,0 +1,78 @@
+getPath('templates');
+ if (!file_exists($dir)) {
+ return;
+ }
+
+ $register = function($newDirs) {
+ $smarty = CRM_Core_Smarty::singleton();
+ $v2 = isset($smarty->_version) && version_compare($smarty->_version, 3, '<');
+ $templateDirs = (array) ($v2 ? $smarty->template_dir : $smarty->getTemplateDir());
+ $templateDirs = array_merge($newDirs, $templateDirs);
+ $templateDirs = array_unique(array_map(function($v) {
+ $v = str_replace(DIRECTORY_SEPARATOR, '/', $v);
+ $v = rtrim($v, '/') . '/';
+ return $v;
+ }, $templateDirs));
+ if ($v2) {
+ $smarty->template_dir = $templateDirs;
+ }
+ else {
+ $smarty->setTemplateDir($templateDirs);
+ }
+ };
+
+ // 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([$dir]);
+ }
+ 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([$dir]);
+ return;
+ }
+
+ // Typical Pageview, Standard Loader: Defer the actual registration for a moment -- to ensure that Smarty is online.
+ // We need to bundle-up all dirs -- Smarty 3/4/5 is inefficient with processing repeated calls to `getTemplateDir()`+`setTemplateDir()`
+ if (!isset(Civi::$statics[__FILE__]['event'])) {
+ Civi::$statics[__FILE__]['event'] = 'civi.smarty-v2.addPaths.' . md5(__FILE__);
+ Civi::dispatcher()->addListener('hook_civicrm_config', function() use ($register) {
+ $dirs = [];
+ $event = \Civi\Core\Event\GenericHookEvent::create(['dirs' => &$dirs]);
+ Civi::dispatcher()->dispatch(Civi::$statics[__FILE__]['event'], $event);
+ $register($dirs);
+ });
+ }
+
+ Civi::dispatcher()->addListener(Civi::$statics[__FILE__]['event'], function($event) use ($mixInfo, $dir) {
+ if ($mixInfo->isActive()) {
+ array_unshift($event->dirs, $dir);
+ }
+ });
+
+};