From 13e9117abd78f08240c4ed12509ef80ab2b9a860 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Tue, 17 Sep 2019 08:48:14 -0400 Subject: [PATCH] Add api4 menu item --- CRM/Upgrade/Incremental/php/FiveNineteen.php | 64 ++++++++++++++------ xml/templates/civicrm_navigation.tpl | 3 +- 2 files changed, 46 insertions(+), 21 deletions(-) diff --git a/CRM/Upgrade/Incremental/php/FiveNineteen.php b/CRM/Upgrade/Incremental/php/FiveNineteen.php index fe4429a84a..588f70106a 100644 --- a/CRM/Upgrade/Incremental/php/FiveNineteen.php +++ b/CRM/Upgrade/Incremental/php/FiveNineteen.php @@ -61,27 +61,51 @@ class CRM_Upgrade_Incremental_php_FiveNineteen extends CRM_Upgrade_Incremental_B // } } - /* - * 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; + } } diff --git a/xml/templates/civicrm_navigation.tpl b/xml/templates/civicrm_navigation.tpl index 4a39b8feb7..82639e761e 100644 --- a/xml/templates/civicrm_navigation.tpl +++ b/xml/templates/civicrm_navigation.tpl @@ -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 -- 2.25.1