Sort api by environments in developer portal

acharyadr
Participant II

In dev portal, i want to list multiple environments and control the APIs displayed as per the selected environment. How can i accomplish this in portal?

0 1 412
1 REPLY 1

In the Drupal developer portal, there is a module that allows you to filter the APIs displayed (Actually we are talking about API Products here) by the environment in which the APIs are deployed, and the hostname of the developer portal. huh?

Well let's suppose you have API Products A, B, C, D, and E. And you have environments "test" and "prod". And then you also have the 3 Drupal portals - dev, test, and live. The module allows you to say

  • "For the dev devportal, show only API products that are deployed to environment test".
  • "For the test devportal, show only API Products that are deployed to environment test"
  • "For the live devportal, show only API products that are deployed to environment prod"

https://github.com/DinoChiesa/Edge-DevPortal-Filter-ApiProducts

This may not be *exactly* what you want; But the technique demonstrated there might give you a good start on building something that fits your needs.


If you don't want to filter the API Products at all, but really just want to group the API Products by Environment, then.... I suggest you look into implementing a hook to alter the form returned by the function devconnect_developer_apps_edit_form(). This function is defined in ~devportal/profiles/apigee/modules/custom/devconnect/devconnect_developer_apps/devconnect_developer_apps.module

It generates the form that renders the dropdown select box, or the set of checkboxes, that allows a user (consumer developer) to select the API Products. You could alter that form to group the API Products by environment, in the dropdown box, or group otherwise if checkboxes are shown.

Implementing a form alter hook is pretty straightforward Drupal stuff. It is described here: https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_form_FORM_ID_alter...

You do need to author some PHP, but it's relatively minor.

the form id is: devconnect_developer_apps_edit_form

So you would need to create a new module, named MY_MODULE (for example) , and then implement a function with this name:

MY_MODULE_form_devconnect_developer_apps_edit_form_alter

Then within that function you can alter the form to sort / group the API Products. For example you could add "separators" to the dropdown for the different environments.

Because it's pretty simple, I implemented this as an illustration for you. See here.

6439-screenshot-20180212-130343.png