Skip to content

Commit

Permalink
CIVIBLD-287 [AUTO] civix upgraded
Browse files Browse the repository at this point in the history
Files changed:
M	info.xml
M	membershiprelationshiptypeeditor.civix.php
M	membershiprelationshiptypeeditor.php
A	mixin/[email protected]
  • Loading branch information
agileware-justin committed Aug 9, 2024
1 parent f188f9e commit f7d4341
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 155 deletions.
7 changes: 6 additions & 1 deletion info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@
</compatibility>
<civix>
<namespace>CRM/Membershiprelationshiptypeeditor</namespace>
<format>22.05.2</format>
<format>23.02.1</format>
</civix>
<mixins>
<mixin>[email protected]</mixin>
<mixin>[email protected]</mixin>
<mixin>[email protected]</mixin>
<mixin>[email protected]</mixin>
</mixins>
<classloader>
<psr0 prefix="CRM_" path="."/>
<psr4 prefix="Civi\" path="Civi"/>
</classloader>
</extension>
116 changes: 9 additions & 107 deletions membershiprelationshiptypeeditor.civix.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class CRM_Membershiprelationshiptypeeditor_ExtensionUtil {
* Translated text.
* @see ts
*/
public static function ts($text, $params = []) {
public static function ts($text, $params = []): string {
if (!array_key_exists('domain', $params)) {
$params['domain'] = [self::LONG_NAME, NULL];
}
Expand All @@ -41,7 +41,7 @@ public static function ts($text, $params = []) {
* 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) {
public static function url($file = NULL): string {
if ($file === NULL) {
return rtrim(CRM_Core_Resources::singleton()->getUrl(self::LONG_NAME), '/');
}
Expand Down Expand Up @@ -84,27 +84,17 @@ public static function findClass($suffix) {
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_config
*/
function _membershiprelationshiptypeeditor_civix_civicrm_config(&$config = NULL) {
function _membershiprelationshiptypeeditor_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.
}

/**
Expand All @@ -114,94 +104,17 @@ function _membershiprelationshiptypeeditor_civix_civicrm_config(&$config = NULL)
*/
function _membershiprelationshiptypeeditor_civix_civicrm_install() {
_membershiprelationshiptypeeditor_civix_civicrm_config();
if ($upgrader = _membershiprelationshiptypeeditor_civix_upgrader()) {
$upgrader->onInstall();
}
}

/**
* Implements hook_civicrm_postInstall().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_postInstall
*/
function _membershiprelationshiptypeeditor_civix_civicrm_postInstall() {
_membershiprelationshiptypeeditor_civix_civicrm_config();
if ($upgrader = _membershiprelationshiptypeeditor_civix_upgrader()) {
if (is_callable([$upgrader, 'onPostInstall'])) {
$upgrader->onPostInstall();
}
}
}

/**
* Implements hook_civicrm_uninstall().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_uninstall
*/
function _membershiprelationshiptypeeditor_civix_civicrm_uninstall() {
_membershiprelationshiptypeeditor_civix_civicrm_config();
if ($upgrader = _membershiprelationshiptypeeditor_civix_upgrader()) {
$upgrader->onUninstall();
}
// Based on <compatibility>, this does not currently require mixin/polyfill.php.
}

/**
* (Delegated) Implements hook_civicrm_enable().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_enable
*/
function _membershiprelationshiptypeeditor_civix_civicrm_enable() {
function _membershiprelationshiptypeeditor_civix_civicrm_enable(): void {
_membershiprelationshiptypeeditor_civix_civicrm_config();
if ($upgrader = _membershiprelationshiptypeeditor_civix_upgrader()) {
if (is_callable([$upgrader, 'onEnable'])) {
$upgrader->onEnable();
}
}
}

/**
* (Delegated) Implements hook_civicrm_disable().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_disable
* @return mixed
*/
function _membershiprelationshiptypeeditor_civix_civicrm_disable() {
_membershiprelationshiptypeeditor_civix_civicrm_config();
if ($upgrader = _membershiprelationshiptypeeditor_civix_upgrader()) {
if (is_callable([$upgrader, 'onDisable'])) {
$upgrader->onDisable();
}
}
}

/**
* (Delegated) Implements 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 https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_upgrade
*/
function _membershiprelationshiptypeeditor_civix_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) {
if ($upgrader = _membershiprelationshiptypeeditor_civix_upgrader()) {
return $upgrader->onUpgrade($op, $queue);
}
}

/**
* @return CRM_Membershiprelationshiptypeeditor_Upgrader
*/
function _membershiprelationshiptypeeditor_civix_upgrader() {
if (!file_exists(__DIR__ . '/CRM/Membershiprelationshiptypeeditor/Upgrader.php')) {
return NULL;
}
else {
return CRM_Membershiprelationshiptypeeditor_Upgrader_Base::instance();
}
// Based on <compatibility>, this does not currently require mixin/polyfill.php.
}

/**
Expand All @@ -220,8 +133,8 @@ function _membershiprelationshiptypeeditor_civix_insert_navigation_menu(&$menu,
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;
Expand Down Expand Up @@ -285,14 +198,3 @@ function _membershiprelationshiptypeeditor_civix_fixNavigationMenuItems(&$nodes,
}
}
}

/**
* (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 _membershiprelationshiptypeeditor_civix_civicrm_entityTypes(&$entityTypes) {
$entityTypes = array_merge($entityTypes, []);
}
47 changes: 0 additions & 47 deletions membershiprelationshiptypeeditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,6 @@ function membershiprelationshiptypeeditor_civicrm_install() {
_membershiprelationshiptypeeditor_civix_civicrm_install();
}

/**
* Implements hook_civicrm_postInstall().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_postInstall
*/
function membershiprelationshiptypeeditor_civicrm_postInstall() {
_membershiprelationshiptypeeditor_civix_civicrm_postInstall();
}

/**
* Implements hook_civicrm_uninstall().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_uninstall
*/
function membershiprelationshiptypeeditor_civicrm_uninstall() {
_membershiprelationshiptypeeditor_civix_civicrm_uninstall();
}

/**
* Implements hook_civicrm_enable().
*
Expand All @@ -48,35 +30,6 @@ function membershiprelationshiptypeeditor_civicrm_enable() {
_membershiprelationshiptypeeditor_civix_civicrm_enable();
}

/**
* Implements hook_civicrm_disable().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_disable
*/
function membershiprelationshiptypeeditor_civicrm_disable() {
_membershiprelationshiptypeeditor_civix_civicrm_disable();
}

/**
* Implements hook_civicrm_upgrade().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_upgrade
*/
function membershiprelationshiptypeeditor_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) {
return _membershiprelationshiptypeeditor_civix_civicrm_upgrade($op, $queue);
}

/**
* Implements hook_civicrm_entityTypes().
*
* Declare entity types provided by this module.
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_entityTypes
*/
function membershiprelationshiptypeeditor_civicrm_entityTypes(&$entityTypes) {
_membershiprelationshiptypeeditor_civix_civicrm_entityTypes($entityTypes);
}

/**
* Enabled relationship type field on edit membership type form.
*
Expand Down
78 changes: 78 additions & 0 deletions mixin/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

/**
* Auto-register "templates/" folder.
*
* @mixinName smarty-v2
* @mixinVersion 1.0.3
* @since 5.59
*
* @deprecated - it turns out that the mixin is not version specific so the 'smarty'
* mixin is preferred over smarty-v2 (they are the same but not having the version
* in the name is less misleading.)
*
* @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($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);
}
});

};

0 comments on commit f7d4341

Please sign in to comment.