You are here

function fontyourface_save_font in @font-your-face 7

Same name and namespace in other branches
  1. 8.3 fontyourface.module \fontyourface_save_font()
  2. 6.2 fontyourface.module \fontyourface_save_font()
  3. 7.2 fontyourface.module \fontyourface_save_font()

Adds or updates font, depending on whether it already exists.

10 calls to fontyourface_save_font()
common_fonts_fontyourface_import in modules/common_fonts/common_fonts.module
Implements hook_fontyourface_import().
fontdeck_fontyourface_import in modules/fontdeck/fontdeck.module
Implements hook_fontyourface_import().
fontsquirrel_fontyourface_enable in modules/fontsquirrel/fontsquirrel.module
Implements hook_fontyourface_enable().
fontsquirrel_fontyourface_import in modules/fontsquirrel/fontsquirrel.module
Implements hook_fontyourface_import().
fonts_com_fontyourface_import in modules/fonts_com/fonts_com.module
Implements hook_fontyourface_import().

... See full list

File

./fontyourface.module, line 956

Code

function fontyourface_save_font(&$font) {
  $tags = $font->tags;
  unset($font->tags);
  $exists = db_query("SELECT fid FROM {fontyourface_font} WHERE url = :url AND provider = :provider", array(
    ':url' => $font->url,
    ':provider' => $font->provider,
  ))
    ->fetchObject();
  if ($exists) {
    $existing_font = fontyourface_get_font($exists->fid);
    $font->fid = $existing_font->fid;

    // Keep status, selector, and tags the same.
    $font->enabled = $existing_font->enabled;
    $font->css_selector = $existing_font->css_selector;
    fontyourface_add_font_tags($font);
    drupal_write_record('fontyourface_font', $font, 'fid');
  }
  else {
    drupal_write_record('fontyourface_font', $font);
  }

  // else
  db_delete('fontyourface_tag_font')
    ->condition('fid', $font->fid)
    ->execute();
  if (!is_array($tags)) {
    $tags = array();
  }

  // if
  fontyourface_add_tags_to_font($tags, $font->fid);
  $font->tags = $tags;
}