Skip to content

Commit

Permalink
Superficial code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Apr 25, 2020
1 parent 55c1339 commit f024de0
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 74 deletions.
93 changes: 50 additions & 43 deletions Civixero.civix.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
* extension.
*/
class CRM_Civixero_ExtensionUtil {

const SHORT_NAME = "Civixero";

const LONG_NAME = "nz.co.fuzion.civixero";

const CLASS_PREFIX = "CRM_Civixero";

/**
Expand All @@ -23,7 +20,6 @@ class CRM_Civixero_ExtensionUtil {
* @param string $text
* Canonical message text (generally en_US).
* @param array $params
*
* @return string
* Translated text.
* @see ts
Expand All @@ -41,7 +37,6 @@ public static function ts($text, $params = []) {
* @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'.
Expand All @@ -59,7 +54,6 @@ public static function url($file = NULL) {
* @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'.
Expand All @@ -74,7 +68,6 @@ public static function path($file = NULL) {
*
* @param string $suffix
* Ex: 'Page_HelloWorld' or 'Page\\HelloWorld'.
*
* @return string
* Ex: 'CRM_Foo_Page_HelloWorld'.
*/
Expand All @@ -89,7 +82,7 @@ public static function findClass($suffix) {
/**
* (Delegated) Implements hook_civicrm_config().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_config
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_config
*/
function _Civixero_civix_civicrm_config(&$config = NULL) {
static $configured = FALSE;
Expand Down Expand Up @@ -119,7 +112,7 @@ function _Civixero_civix_civicrm_config(&$config = NULL) {
*
* @param $files array(string)
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_xmlMenu
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_xmlMenu
*/
function _Civixero_civix_civicrm_xmlMenu(&$files) {
foreach (_Civixero_civix_glob(__DIR__ . '/xml/Menu/*.xml') as $file) {
Expand All @@ -130,7 +123,7 @@ function _Civixero_civix_civicrm_xmlMenu(&$files) {
/**
* Implements hook_civicrm_install().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_install
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_install
*/
function _Civixero_civix_civicrm_install() {
_Civixero_civix_civicrm_config();
Expand All @@ -142,7 +135,7 @@ function _Civixero_civix_civicrm_install() {
/**
* Implements hook_civicrm_postInstall().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_postInstall
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_postInstall
*/
function _Civixero_civix_civicrm_postInstall() {
_Civixero_civix_civicrm_config();
Expand All @@ -156,7 +149,7 @@ function _Civixero_civix_civicrm_postInstall() {
/**
* Implements hook_civicrm_uninstall().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_uninstall
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_uninstall
*/
function _Civixero_civix_civicrm_uninstall() {
_Civixero_civix_civicrm_config();
Expand All @@ -168,7 +161,7 @@ function _Civixero_civix_civicrm_uninstall() {
/**
* (Delegated) Implements hook_civicrm_enable().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_enable
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_enable
*/
function _Civixero_civix_civicrm_enable() {
_Civixero_civix_civicrm_config();
Expand All @@ -182,7 +175,7 @@ function _Civixero_civix_civicrm_enable() {
/**
* (Delegated) Implements hook_civicrm_disable().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_disable
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_disable
* @return mixed
*/
function _Civixero_civix_civicrm_disable() {
Expand All @@ -203,7 +196,7 @@ function _Civixero_civix_civicrm_disable() {
* @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
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_upgrade
*/
function _Civixero_civix_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) {
if ($upgrader = _Civixero_civix_upgrader()) {
Expand All @@ -224,13 +217,13 @@ function _Civixero_civix_upgrader() {
}

/**
* Search directory tree for files which match a glob pattern
* 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()
*
* @param $dir string, base dir
* @param $pattern string, glob pattern, eg "*.txt"
* @param string $dir base dir
* @param string $pattern , glob pattern, eg "*.txt"
*
* @return array(string)
*/
Expand Down Expand Up @@ -262,26 +255,26 @@ function _Civixero_civix_find_files($dir, $pattern) {
}
return $result;
}

/**
* (Delegated) Implements hook_civicrm_managed().
*
* Find any *.mgd.php files, merge their content, and return.
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_managed
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_managed
*/
function _Civixero_civix_civicrm_managed(&$entities) {
$mgdFiles = _Civixero_civix_find_files(__DIR__, '*.mgd.php');
sort($mgdFiles);
foreach ($mgdFiles as $file) {
$es = include $file;
foreach ($es as $e) {
if (empty($e['module'])) {
$e['module'] = E::LONG_NAME;
}
$entities[] = $e;
if (empty($e['params']['version'])) {
$e['params']['version'] = '3';
}
$entities[] = $e;
}
}
}
Expand All @@ -293,7 +286,7 @@ function _Civixero_civix_civicrm_managed(&$entities) {
*
* Note: This hook only runs in CiviCRM 4.4+.
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_caseTypes
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_caseTypes
*/
function _Civixero_civix_civicrm_caseTypes(&$caseTypes) {
if (!is_dir(__DIR__ . '/xml/case')) {
Expand All @@ -304,8 +297,7 @@ function _Civixero_civix_civicrm_caseTypes(&$caseTypes) {
$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);
throw new CRM_Core_Exception($errorMessage);
}
$caseTypes[$name] = [
'module' => E::LONG_NAME,
Expand All @@ -322,7 +314,7 @@ function _Civixero_civix_civicrm_caseTypes(&$caseTypes) {
*
* Note: This hook only runs in CiviCRM 4.5+.
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_angularModules
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_angularModules
*/
function _Civixero_civix_civicrm_angularModules(&$angularModules) {
if (!is_dir(__DIR__ . '/ang')) {
Expand All @@ -340,6 +332,25 @@ function _Civixero_civix_civicrm_angularModules(&$angularModules) {
}
}

/**
* (Delegated) Implements hook_civicrm_themes().
*
* Find any and return any files matching "*.theme.php"
*/
function _Civixero_civix_civicrm_themes(&$themes) {
$files = _Civixero_civix_glob(__DIR__ . '/*.theme.php');
foreach ($files as $file) {
$themeMeta = include $file;
if (empty($themeMeta['name'])) {
$themeMeta['name'] = preg_replace(':\.theme\.php$:', '', basename($file));
}
if (empty($themeMeta['ext'])) {
$themeMeta['ext'] = E::LONG_NAME;
}
$themes[$themeMeta['name']] = $themeMeta;
}
}

/**
* Glob wrapper which is guaranteed to return an array.
*
Expand All @@ -349,7 +360,6 @@ function _Civixero_civix_civicrm_angularModules(&$angularModules) {
* This wrapper provides consistency.
*
* @link http://php.net/glob
*
* @param string $pattern
*
* @return array, possibly empty
Expand All @@ -363,16 +373,20 @@ function _Civixero_civix_glob($pattern) {
* Inserts a navigation menu item at a given place in the hierarchy.
*
* @param array $menu - menu hierarchy
* @param string $path - path where insertion should happen (ie. Administer/System Settings)
* @param array $item - menu you need to insert (parent/child attributes will be filled for you)
* @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 _Civixero_civix_insert_navigation_menu(&$menu, $path, $item) {
// If we are done going down the path, insert menu
if (empty($path)) {
$menu[] = [
'attributes' => array_merge([
'label' => CRM_Utils_Array::value('name', $item),
'active' => 1,
'label' => CRM_Utils_Array::value('name', $item),
'active' => 1,
], $item),
];
return TRUE;
Expand All @@ -387,7 +401,7 @@ function _Civixero_civix_insert_navigation_menu(&$menu, $path, $item) {
if (!isset($entry['child'])) {
$entry['child'] = [];
}
$found = _Civixero_civix_insert_navigation_menu($entry['child'], implode('/', $path), $item, $key);
$found = _Civixero_civix_insert_navigation_menu($entry['child'], implode('/', $path), $item);
}
}
return $found;
Expand All @@ -409,7 +423,7 @@ function _Civixero_civix_navigationMenu(&$nodes) {
*/
function _Civixero_civix_fixNavigationMenu(&$nodes) {
$maxNavID = 1;
array_walk_recursive($nodes, function ($item, $key) use (&$maxNavID) {
array_walk_recursive($nodes, function($item, $key) use (&$maxNavID) {
if ($key === 'navID') {
$maxNavID = max($maxNavID, $item);
}
Expand Down Expand Up @@ -440,17 +454,11 @@ function _Civixero_civix_fixNavigationMenuItems(&$nodes, &$maxNavID, $parentID)
/**
* (Delegated) Implements hook_civicrm_alterSettingsFolders().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_alterSettingsFolders
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_alterSettingsFolders
*/
function _Civixero_civix_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) {
static $configured = FALSE;
if ($configured) {
return;
}
$configured = TRUE;

$settingsDir = __DIR__ . DIRECTORY_SEPARATOR . 'settings';
if (is_dir($settingsDir) && !in_array($settingsDir, $metaDataFolders)) {
if (!in_array($settingsDir, $metaDataFolders) && is_dir($settingsDir)) {
$metaDataFolders[] = $settingsDir;
}
}
Expand All @@ -460,10 +468,9 @@ function _Civixero_civix_civicrm_alterSettingsFolders(&$metaDataFolders = NULL)
*
* Find any *.entityType.php files, merge their content, and return.
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_entityTypes
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_entityTypes
*/

function _Civixero_civix_civicrm_entityTypes(&$entityTypes) {
$entityTypes = array_merge($entityTypes, [
]);
$entityTypes = array_merge($entityTypes, []);
}
Loading

0 comments on commit f024de0

Please sign in to comment.