You are here

function adobe_edge_fonts_fontyourface_import in @font-your-face 8.3

Implements hook_fontyourface_import().

File

modules/adobe_edge_fonts/adobe_edge_fonts.module, line 60
Adobe Edge Fonts module file.

Code

function adobe_edge_fonts_fontyourface_import($font_context = []) {
  $context = $font_context;
  if (empty($context['sandbox'])) {
    $context['sandbox']['fonts'] = _adobe_edge_fonts_get_fonts_from_api();
    $context['sandbox']['progress'] = 0;
    $context['sandbox']['max'] = count($context['sandbox']['fonts']);
  }
  $font = array_pop($context['sandbox']['fonts']);
  if (!empty($font)) {
    fontyourface_save_font($font);
    $context['message'] = "Imported {$context['sandbox']['progress']} of {$context['sandbox']['max']}";
    $context['sandbox']['progress'] = $context['sandbox']['max'] - count($context['sandbox']['fonts']);
    $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
  }
  else {
    Drupal::messenger()
      ->addMessage(t('Imported @count fonts from Adobe Edge', [
      '@count' => $context['sandbox']['progress'],
    ]));
  }
  return $context;
}