You are here

function fontyourface_save_and_generate_font_display_css in @font-your-face 8.3

Saves and generates font file based on font display config entity data.

Parameters

Drupal\fontyourface\FontDisplayInterface $style: Custom config font display entity.

Return value

bool TRUE if files save successfully. Throw any errors otherwise.

2 calls to fontyourface_save_and_generate_font_display_css()
FontDisplayForm::save in src/Form/FontDisplayForm.php
Form submission handler for the 'save' action.
fontyourface_update_8004 in ./fontyourface.install
Updates fontyourface font displays to be stored in files.

File

./fontyourface.module, line 417
Contains fontyourface.module..

Code

function fontyourface_save_and_generate_font_display_css(FontDisplayInterface $style) {
  $directory = file_build_uri('fontyourface/font_display');
  \Drupal::service('file_system')
    ->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS);
  $font = $style
    ->getFont();
  $css_file = $directory . '/' . $style
    ->id() . '.css';
  $css_file_data = $style
    ->getSelectors() . ' { ' . fontyourface_font_css($font, $style) . ' }';
  \Drupal::service('file_system')
    ->saveData($css_file_data, $css_file, FileSystemInterface::EXISTS_REPLACE);
  return TRUE;
}