Skip to content

Commit

Permalink
Add api4 menu item
Browse files Browse the repository at this point in the history
  • Loading branch information
colemanw committed Sep 17, 2019
1 parent 0b873c9 commit 82d8e04
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 24 deletions.
64 changes: 44 additions & 20 deletions CRM/Upgrade/Incremental/php/FiveNineteen.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,27 +61,51 @@ public function setPostUpgradeMessage(&$postUpgradeMessage, $rev) {
// }
}

/*
* Important! All upgrade functions MUST add a 'runSql' task.
* Uncomment and use the following template for a new upgrade version
* (change the x in the function name):
/**
* Upgrade function.
*
* @param string $rev
*/
public function upgrade_5_19_alpha1($rev) {
$this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
$this->addTask('Add api4 menu', 'api4Menu');
}

// /**
// * Upgrade function.
// *
// * @param string $rev
// */
// public function upgrade_5_0_x($rev) {
// $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
// $this->addTask('Do the foo change', 'taskFoo', ...);
// // Additional tasks here...
// // Note: do not use ts() in the addTask description because it adds unnecessary strings to transifex.
// // The above is an exception because 'Upgrade DB to %1: SQL' is generic & reusable.
// }

// public static function taskFoo(CRM_Queue_TaskContext $ctx, ...) {
// return TRUE;
// }
/**
* Add menu item for api4 explorer; rename v3 explorer menu item.
*
* @param \CRM_Queue_TaskContext $ctx
* @return bool
*/
public static function api4Menu(CRM_Queue_TaskContext $ctx) {
try {
$v3Item = civicrm_api3('Navigation', 'get', [
'name' => 'API Explorer',
'return' => ['id', 'parent_id', 'weight'],
'sequential' => 1,
'domain_id' => CRM_Core_Config::domainID(),
'api.Navigation.create' => ['label' => ts("Api Explorer v3")],
]);
$existing = civicrm_api3('Navigation', 'getcount', [
'name' => "Api Explorer v4",
'domain_id' => CRM_Core_Config::domainID(),
]);
if (!$existing) {
civicrm_api3('Navigation', 'create', [
'parent_id' => $v3Item['values'][0]['parent_id'] ?? 'Developer',
'label' => ts("Api Explorer v4"),
'weight' => $v3Item['values'][0]['weight'] ?? 2,
'name' => "Api Explorer v4",
'permission' => "administer CiviCRM",
'url' => "civicrm/api4#/explorer",
'is_active' => 1,
]);
}
}
catch (Exception $e) {
// Couldn't create menu item.
}
return TRUE;
}

}
4 changes: 2 additions & 2 deletions CRM/Utils/JS.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public static function decode($js) {
if ($last === $first && ($first === "'" || $first === '"')) {
// Use a temp placeholder for escaped backslashes
$backslash = chr(0) . 'backslash' . chr(0);
return str_replace(['\\\\', "\\'", '\\"', '\\&', '\\/', $backslash], [$backslash, "'", '"', '&', '/', '\\'], substr($js, 1, -1));
$js = '"' . str_replace(['\\\\', "\\'", '\\"', '"', '\\&', '\\/', $backslash], [$backslash, "'", '"', '\\"', '&', '/', '\\'], substr($js, 1, -1)) . '"';
}
if (($first === '{' && $last === '}') || ($first === '[' && $last === ']')) {
$obj = self::getRawProps($js);
Expand All @@ -157,7 +157,7 @@ public static function decode($js) {
}
return $obj;
}
return json_decode($js);
return json_decode($js, TRUE);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/CRM/Utils/JSTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ public static function objectExamples() {
],
[
'{"some\"key": typeof foo === \'number\' ? true : false , "O\'Really?": ",((,", \'A"quote"\': 1 + 1 , "\\\\\\&\\/" : 0}',
['some"key' => 'typeof foo === \'number\' ? true : false', "O'Really?" => '",((,"', 'A"quote"' => '1 + 1', '\\&/' => '0'],
['some"key' => 'typeof foo === \'number\' ? true : false', "O'Really?" => '",((,"', 'A"quote"' => '1 + 1', '\\\\&/' => '0'],
'{\'some"key\': typeof foo === \'number\' ? true : false, "O\'Really?": ",((,", \'A"quote"\': 1 + 1, "\\\\&/": 0}',
],
[
Expand Down
3 changes: 2 additions & 1 deletion xml/templates/civicrm_navigation.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,8 @@ SET @devellastID:=LAST_INSERT_ID();
INSERT INTO civicrm_navigation
( domain_id, url, label, name, permission, permission_operator, parent_id, is_active, has_separator, weight )
VALUES
( @domainID, 'civicrm/api', '{ts escape="sql" skip="true"}API Explorer{/ts}','API Explorer', 'administer CiviCRM', '', @devellastID, '1', NULL, 1 ),
( @domainID, 'civicrm/api', '{ts escape="sql" skip="true"}Api Explorer v3{/ts}', 'API Explorer', 'administer CiviCRM', '', @devellastID, '1', NULL, 1 ),
( @domainID, 'civicrm/api4#/explorer', '{ts escape="sql" skip="true"}Api Explorer v4{/ts}', 'Api Explorer v4', 'administer CiviCRM', '', @devellastID, '1', NULL, 2 ),
( @domainID, 'https://civicrm.org/developer-documentation?src=iam', '{ts escape="sql" skip="true"}Developer Docs{/ts}', 'Developer Docs', 'administer CiviCRM', '', @devellastID, '1', NULL, 3 );

INSERT INTO civicrm_navigation
Expand Down

0 comments on commit 82d8e04

Please sign in to comment.