Skip to content

Commit

Permalink
Issue eileenmcnaughton#22 use a localTokens variable to prevent remov…
Browse files Browse the repository at this point in the history
…al of tokens of other extensions
  • Loading branch information
kainuk committed Apr 4, 2018
1 parent a17d2b5 commit 47d5117
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions civitoken.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,27 +119,29 @@ function civitoken_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) {
}

/**
* implementation of CiviCRM hook
*/
* implementation of CiviCRM hook
*/
function civitoken_civicrm_tokens(&$tokens) {
civitoken_civicrm_tokens_all($tokens);
$localTokens = array();
civitoken_civicrm_tokens_all($localTokens);
$setting = civicrm_api3('Setting', 'get', ['return' => 'civitoken_enabled_tokens', 'sequential' => 1])['values'][0];

if (empty($setting) || empty($setting['civitoken_enabled_tokens'])) {
// Treat un-configured as 'all enabled'.
return;
}

foreach ($tokens as $category => $tokenSubset) {
foreach ($localTokens as $category => $tokenSubset) {
foreach ($tokenSubset as $key => $token) {
if (!in_array($key, $setting['civitoken_enabled_tokens'])) {
unset($tokens[$category][$key]);
unset($localTokens[$category][$key]);
}
}
if (empty($tokens[$category])) {
unset($tokens[$category]);
if (empty($localTokens[$category])) {
unset($localTokens[$category]);
}
}
$tokens = array_merge($tokens,$localTokens);
}

/**
Expand Down

0 comments on commit 47d5117

Please sign in to comment.