You are here

function fonts_com_set_font_selector in @font-your-face 7.2

Sets selector on font.

1 call to fonts_com_set_font_selector()
fonts_com_fontyourface_selector_update in modules/fonts_com/fonts_com.module
Implements hook_fontyourface_selector_update().

File

modules/fonts_com/api.inc, line 510
API functions.

Code

function fonts_com_set_font_selector($project_id, $font_id, $selector) {
  fonts_com_add_selector_to_project($project_id, $selector);
  $project_selectors = fonts_com_get_selectors_in_project($project_id);
  $selector_id = FALSE;
  foreach ($project_selectors as $project_selector) {
    if ($project_selector->SelectorTag == $selector) {
      $selector_id = $project_selector->SelectorID;
    }
    elseif ($project_selector->SelectorFontID == $font_id) {
      fonts_com_delete_selector_in_product($project_id, $project_selector->SelectorID);
    }

    // elseif
  }

  // foreach
  if ($selector_id) {
    $path = '/rest/json/Selectors/?wfspid=' . $project_id;
    $response = drupal_http_request(FONTS_COM_API_BASE_URL . $path, array(
      'headers' => fonts_com_api_headers($path),
      'method' => 'PUT',
      'data' => 'wfsselector_ids=' . $selector_id . '&wfsfont_ids=' . $font_id,
    ));
    if ($response->code == 200) {
      fonts_com_publish();
      return TRUE;
    }
    else {
      drupal_set_message(t('There was an error adding a CSS selector on Fonts.com.'), 'error');
      fontyourface_log('Invalid drupal_http_request response: @response', array(
        '@response' => print_r($response, TRUE),
      ));
    }

    // else
  }

  // if
  return FALSE;
}