Add api4 menu item
authorColeman Watts <coleman@civicrm.org>
Tue, 17 Sep 2019 12:48:14 +0000 (08:48 -0400)
committerColeman Watts <coleman@civicrm.org>
Tue, 17 Sep 2019 22:48:46 +0000 (18:48 -0400)
CRM/Upgrade/Incremental/php/FiveNineteen.php
xml/templates/civicrm_navigation.tpl

index fe4429a84acb31e0af2cdec27f24713ea8c28d91..588f70106a44440c4393e4549e98d705c33307dd 100644 (file)
@@ -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;
+  }
 
 }
index 4a39b8feb7236f1ba77a2f6aeb81118a96d1bb1a..82639e761e97f4a934c41b7de1edd845c7d86b57 100644 (file)
@@ -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