function fontscom_api_add_font_to_current_project in @font-your-face 8.3
Adds font to fonts.com project package.
Parameters
int $fid: Fonts.com font ID.
Return value
bool True if font added successfully. FALSE otherwise.
1 call to fontscom_api_add_font_to_current_project()
- fontscom_api_entity_presave in modules/
fontscom_api/ fontscom_api.module - Implements hook_entity_presave().
File
- modules/
fontscom_api/ fontscom_api.module, line 484 - Fonts.com API module file.
Code
function fontscom_api_add_font_to_current_project($fid) {
try {
$config = \Drupal::config('fontscom_api.settings');
$path = '/rest/json/Fonts/?wfspid=' . $config
->get('project');
$uri = FONTSCOM_API_BASE_URL . $path;
$response = \Drupal::httpClient()
->post($uri, [
'headers' => fontscom_api_headers($path),
'verify' => FALSE,
'body' => 'wfsfid=' . $fid,
]);
$data = json_decode((string) $response
->getBody());
fontscom_api_publish_updated_project();
return TRUE;
} catch (Exception $e) {
Drupal::messenger()
->addMessage(t('There was an error adding font to Fonts.com project. Error: %error', [
'%error' => Psr7\str($e
->getResponse()),
]), 'error');
return FALSE;
}
}