You are here

function fontscom_api_get_all_enabled_fonts in @font-your-face 8.3

Retrieves list of all enabled fonts from Fonts.com.

Return value

array Array of enabled fonts.com font objects.

2 calls to fontscom_api_get_all_enabled_fonts()
fontscom_api_entity_presave in modules/fontscom_api/fontscom_api.module
Implements hook_entity_presave().
fontscom_api_fontyourface_import in modules/fontscom_api/fontscom_api.module
Implements hook_fontyourface_import().

File

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

Code

function fontscom_api_get_all_enabled_fonts() {
  try {
    $config = \Drupal::config('fontscom_api.settings');
    $path = '/rest/json/Fonts/?wfspid=' . $config
      ->get('project');
    $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 total Font count from Fonts.com. Error: %error', [
      '%error' => $e
        ->getMessage(),
    ]), 'error');
    return FALSE;
  }
  $enabled_fonts = [];
  foreach ($data->Fonts->Font as $font) {
    $enabled_fonts[$font->FontID] = $font;
  }
  return $enabled_fonts;
}