You are here

public function FirebaseConfigManager::getAvailableConfigs in TMGMT Translator Smartling 8.4

Same name and namespace in other branches
  1. 8.3 src/Smartling/ConfigManager/FirebaseConfigManager.php \Drupal\tmgmt_smartling\Smartling\ConfigManager\FirebaseConfigManager::getAvailableConfigs()

Returns array of available smartling providers with enabled notifications.

Return value

array

Overrides SmartlingConfigManager::getAvailableConfigs

File

src/Smartling/ConfigManager/FirebaseConfigManager.php, line 47
FirebaseConfigManager.

Class

FirebaseConfigManager
Class FirebaseConfigManager.

Namespace

Drupal\tmgmt_smartling\Smartling\ConfigManager

Code

public function getAvailableConfigs() {
  $firebaseConfigs = [];
  $configs = parent::getAvailableConfigs();
  foreach ($configs as $config) {
    $provider_settings = $config
      ->get('settings');
    if (empty($provider_settings['enable_notifications'])) {
      continue;
    }
    $cachedData = $this->defaultCache
      ->get("tmgmt_smartling.firebase_config.{$provider_settings["project_id"]}");
    if (empty($cachedData)) {
      try {
        $this->apiWrapper
          ->setSettings($provider_settings);
        $project_details = $this->apiWrapper
          ->getApi("project")
          ->getProjectDetails();
        $data = $this->apiWrapper
          ->getApi("progress")
          ->getToken($project_details["accountUid"]);
        $data["accountUid"] = $project_details["accountUid"];
        $data["projectId"] = $provider_settings["project_id"];
        $firebaseConfigs[] = $data;
        $this->defaultCache
          ->set("tmgmt_smartling.firebase_config.{$provider_settings["project_id"]}", $data, time() + 3600, [
          "tmgmt_smartling:firebase_config:{$provider_settings["project_id"]}",
        ]);
      } catch (\Exception $e) {

        // Empty settings, can't fetch project details.
      }
    }
    else {
      $firebaseConfigs[] = $cachedData->data;
    }
  }
  return $firebaseConfigs;
}