You are here

function fontyourface_save_font in @font-your-face 8.3

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

Saves/updates font.

Parameters

object $font_data: Simple stdclass rep of font for saving.

Return value

Drupal\fontyourface\Entity\Font Newly saved/updated font.

7 calls to fontyourface_save_font()
adobe_edge_fonts_fontyourface_import in modules/adobe_edge_fonts/adobe_edge_fonts.module
Implements hook_fontyourface_import().
fontscom_api_fontyourface_import in modules/fontscom_api/fontscom_api.module
Implements hook_fontyourface_import().
fontsquirrel_api_fontyourface_import in modules/fontsquirrel_api/fontsquirrel_api.module
Implements hook_fontyourface_import().
google_fonts_api_fontyourface_import in modules/google_fonts_api/google_fonts_api.module
Implements hook_fontyourface_import().
local_fonts_entity_presave in modules/local_fonts/local_fonts.module
Implements hook_entity_presave().

... See full list

File

./fontyourface.module, line 268
Contains fontyourface.module..

Code

function fontyourface_save_font($font_data) {
  $font = Font::loadByUrl($font_data->url);
  if (empty($font)) {
    $font = Font::create();
  }
  $font->pid = $font_data->provider;
  $font->url = $font_data->url;
  $font->name = $font_data->name;
  $font->css_family = !empty($font_data->css_family) ? $font_data->css_family : '';
  $font->css_style = !empty($font_data->css_style) ? $font_data->css_style : '';
  $font->css_weight = !empty($font_data->css_weight) ? $font_data->css_weight : '';
  $font->foundry = !empty($font_data->foundry) ? $font_data->foundry : '';
  $font->foundry_url = !empty($font_data->foundry_url) ? $font_data->foundry_url : '';
  $font->license = !empty($font_data->license) ? $font_data->license : '';
  $font->license_url = !empty($font_data->license_url) ? $font_data->license_url : '';
  $font->designer = !empty($font_data->designer) ? $font_data->designer : '';
  $font->designer_url = !empty($font_data->designer_url) ? $font_data->designer_url : '';
  if (!empty($font_data->classification)) {
    $font->field_classification = [];
    foreach ($font_data->classification as $classification) {
      $font->field_classification[] = [
        'target_id' => _fontyourface_get_vocabulary_term($classification, 'font_classification'),
      ];
    }
  }
  if (!empty($font_data->language)) {
    $font->field_supported_languages = [];
    foreach ($font_data->language as $language) {
      $font->field_supported_languages[] = [
        'target_id' => _fontyourface_get_vocabulary_term($language, 'languages_supported'),
      ];
    }
  }
  $font->tags = [];
  if (!empty($font_data->foundry)) {
    $font->field_tags[] = [
      'target_id' => _fontyourface_get_vocabulary_term($font_data->foundry, 'font_foundry'),
    ];
  }
  if (!empty($font_data->designer)) {
    $font->field_tags[] = [
      'target_id' => _fontyourface_get_vocabulary_term($font_data->designer, 'font_designer'),
    ];
  }
  $font
    ->setMetadata(!empty($font_data->metadata) ? $font_data->metadata : []);
  $font->status = FALSE;
  if ($font
    ->isActivated()) {
    $font->status = TRUE;
  }
  $font
    ->save();
  return $font;
}