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 b7c71a3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 21 deletions.
58 changes: 38 additions & 20 deletions CRM/Upgrade/Incremental/php/FiveNineteen.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,27 +61,45 @@ 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")],
]);
civicrm_api3('Navigation', 'create', [
'parent_id' => $v3Item['values'][0]['parent_id'],
'label' => ts("Api Explorer v4"),
'weight' => $v3Item['values'][0]['weight'] + 1,
'name' => "Api Explorer v4",
'permission' => "administer CiviCRM",
'url' => "civicrm/api4#/explorer",
'is_active' => 1,
]);
}
catch (Exception $e) {
// Couldn't create menu item.
}
return TRUE;
}

}
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 b7c71a3

Please sign in to comment.