You are here

function fontscom_api_remove_font_from_current_project in @font-your-face 8.3

Removes font from fonts.com project package.

Parameters

int $fid: Fonts.com font ID.

Return value

bool True if font removed successfully. FALSE otherwise.

1 call to fontscom_api_remove_font_from_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 513
Fonts.com API module file.

Code

function fontscom_api_remove_font_from_current_project($fid) {
  try {
    $config = \Drupal::config('fontscom_api.settings');
    $path = '/rest/json/Fonts/?wfspid=' . $config
      ->get('project') . '&wfsfid=' . $fid;
    $uri = FONTSCOM_API_BASE_URL . $path;
    $response = \Drupal::httpClient()
      ->delete($uri, [
      'headers' => fontscom_api_headers($path),
      'verify' => FALSE,
    ]);
    $data = json_decode((string) $response
      ->getBody());
    fontscom_api_publish_updated_project();
    return TRUE;
  } catch (Exception $e) {
    Drupal::messenger()
      ->addMessage(t('There was an error removing font from Fonts.com project. Error: %error', [
      '%error' => Psr7\str($e
        ->getResponse()),
    ]), 'error');
    return FALSE;
  }
}