You are here

function local_fonts_entity_presave in @font-your-face 8.3

Implements hook_entity_presave().

File

modules/local_fonts/local_fonts.module, line 50
Local Fonts module file.

Code

function local_fonts_entity_presave(EntityInterface $entity) {
  if ($entity instanceof LocalFontConfigEntity) {

    // Save and generate necessary font files.
    local_fonts_save_and_generate_css($entity);

    // Save Font in FYF DB storage.
    $font_data = new \stdClass();
    $font_data->name = $entity
      ->label();
    $font_data->url = 'local_fonts://' . $entity
      ->id();
    $font_data->provider = 'local_fonts';
    $font_data->css_family = $entity->font_family;
    $font_data->css_weight = $entity->font_weight;
    $font_data->css_style = $entity->font_style;
    $font_data->classification = array_filter($entity->font_classification);
    $font_data->language = [
      'English',
    ];
    $font_data->metadata = [
      'id' => $entity
        ->id(),
    ];
    fontyourface_save_font($font_data);
  }
}