diff --git a/modules/apigee_m10n_teams/apigee_m10n_teams.install b/modules/apigee_m10n_teams/apigee_m10n_teams.install index 682f52d5..0acc0f4d 100644 --- a/modules/apigee_m10n_teams/apigee_m10n_teams.install +++ b/modules/apigee_m10n_teams/apigee_m10n_teams.install @@ -30,3 +30,41 @@ function apigee_m10n_teams_install() { user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, MonetizationTeamsInterface::DEFAULT_AUTHENTICATED_PERMISSIONS); } } + +/** + * Implements hook_requirements(). + */ +function apigee_m10n_teams_requirements($phase) { + $requirements = []; + + if ($phase == 'install' || $phase == 'runtime') { + try { + /** @var \Drupal\apigee_edge\SDKConnectorInterface $sdk_connector */ + $sdk_connector = \Drupal::service('apigee_edge.sdk_connector'); + $org_controller = \Drupal::service('apigee_edge.controller.organization'); + /* @var \Apigee\Edge\Api\Management\Entity\Organization $organization */ + $organization = $org_controller->load($sdk_connector->getOrganization()); + if ($organization && $org_controller->isOrganizationApigeeX()) { + // AppGroup APIs are not supported in Apigee X / Hybrid orgs with monetization enabled. + if ($organization->getAddonsConfig() && $organization->getAddonsConfig()->getMonetizationConfig() && TRUE === $organization->getAddonsConfig()->getMonetizationConfig()->getEnabled()) { + $url = [ + ':url' => 'https://cloud.google.com/apigee/docs/api-platform/publish/organizing-client-app-ownership?hl=en#appgroups-limitations-and-known-issues', + ]; + $message = ($phase == 'runtime') ? + t("The Apigee Monetization Teams module functionality is not available for monetization enabled org on Apigee X / Hybrid and should be uninstalled, because AppGroup APIs are not supported in Apigee X / Hybrid orgs with monetization enabled.", $url) : + t("The Apigee Monetization Teams module functionality is not available for monetization enabled org on Apigee X / Hybrid because AppGroup APIs are not supported in Apigee X / Hybrid orgs with monetization enabled.", $url); + $requirements['apigee_edge_teams_not_supported'] = [ + 'title' => t('Apigee Edge Teams'), + 'description' => $message, + 'severity' => REQUIREMENT_ERROR, + ]; + } + } + } + catch (\Exception $exception) { + // Do nothing if connection to Edge is not available. + } + } + + return $requirements; +}