You are here

function fontsquirrel_api_get_font_family_info in @font-your-face 8.3

Get font family information from Font Squirrel.

Parameters

object $font_import: Initial font package data from Font Squirrel.

Return value

object Font family information from Font Squirrel.

1 call to fontsquirrel_api_get_font_family_info()
fontsquirrel_api_fontyourface_import in modules/fontsquirrel_api/fontsquirrel_api.module
Implements hook_fontyourface_import().

File

modules/fontsquirrel_api/fontsquirrel_api.module, line 240
Font Squirrel API module file.

Code

function fontsquirrel_api_get_font_family_info($font_import) {
  try {
    $uri = 'https://www.fontsquirrel.com/api/familyinfo/' . $font_import->family_urlname;
    $response = \Drupal::httpClient()
      ->get($uri, [
      'headers' => [
        'Accept' => 'text/plain',
      ],
    ]);
    $data = json_decode($response
      ->getBody());
  } catch (RequestException $e) {
    Drupal::messenger()
      ->addMessage(t('There was an error downloading font list from Font Squirrel.'), 'error');
    fontyourface_log('Invalid drupal_http_request response: @response', [
      '@response' => $e
        ->getMessage(),
    ]);
    return FALSE;
  }
  return $data;
}