You are here

function fontscom_api_get_projects in @font-your-face 8.3

Returns list of projects.

1 call to fontscom_api_get_projects()
fontscom_api_form_font_settings_alter in modules/fontscom_api/fontscom_api.module
Implements hook_form_alter().

File

modules/fontscom_api/fontscom_api.module, line 296
Fonts.com API module file.

Code

function fontscom_api_get_projects() {
  $projects = [];
  try {
    $path = '/rest/json/Projects/?wfspstart=0&wfsplimit=100';
    $uri = FONTSCOM_API_BASE_URL . $path;
    $response = \Drupal::httpClient()
      ->get($uri, [
      'headers' => fontscom_api_headers($path),
      'verify' => FALSE,
    ]);
    $data = json_decode((string) $response
      ->getBody());
  } catch (Exception $e) {
    Drupal::messenger()
      ->addMessage(t('There was an error retrieving project list from Fonts.com. Error: %error', [
      '%error' => $e
        ->getMessage(),
    ]), 'error');
    return [];
  }
  if ($data->Projects->TotalRecords > 0) {
    $project = $data->Projects->Project;
    $projects = fontscom_api_unknown_to_array($project);
  }
  return $projects;
}