function fontscom_api_get_all_fonts in @font-your-face 8.3
Gets a list of all fonts, in given range.
Parameters
int $start: Pager request start value.
int $limit: Pager request limit. Max 50.
Return value
array Array of fonts.com font objects.
1 call to fontscom_api_get_all_fonts()
- fontscom_api_fontyourface_import in modules/
fontscom_api/ fontscom_api.module - Implements hook_fontyourface_import().
File
- modules/
fontscom_api/ fontscom_api.module, line 348 - Fonts.com API module file.
Code
function fontscom_api_get_all_fonts($start = 0, $limit = 50) {
$result = [
'fonts' => [],
'count' => FALSE,
];
$query = [
'wfspstart' => $start,
'wfsplimit' => $limit,
'wfsCSS' => 1,
];
$filters = fontscom_api_get_allowed_api_filters();
if ($filters->FreeOrPaid == 0) {
$query['wfsfree'] = 'TRUE';
}
try {
$path = '/rest/json/AllFonts/?' . UrlHelper::buildQuery($query);
$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 importing fonts from Fonts.com. Error: %error', [
'%error' => $e
->getMessage(),
]), 'error');
return FALSE;
}
return $data->AllFonts->Font;
}