You are here

function fontyourface_font_css in @font-your-face 8.3

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

Creates CSS with any properties set on font.

Parameters

Drupal\fontyourface\FontInterface $font: The font object.

Drupal\fontyourface\FontDisplayInterface $font_style: The font display object.

string $separator: Approach to separating the resulting css.

Return value

string The font-family css.

3 calls to fontyourface_font_css()
FontDisplayForm::form in src/Form/FontDisplayForm.php
Gets the actual form array to be built.
fontyourface_preprocess_font in ./fontyourface.module
Prepares variables for Font templates.
fontyourface_save_and_generate_font_display_css in ./fontyourface.module
Saves and generates font file based on font display config entity data.

File

./fontyourface.module, line 334
Contains fontyourface.module..

Code

function fontyourface_font_css(FontInterface $font, FontDisplayInterface $font_style = NULL, $separator = ' ') {
  $css = \Drupal::moduleHandler()
    ->invokeAll('fontyourface_font_css', [
    $font,
    $font_style,
    $separator,
  ]);
  if (!empty($css)) {
    return implode("\n", $css);
  }
  $css = [];

  // Enclose font family definition in single quotes if not already enclosed.
  if ($font->css_family->value[0] === "'") {
    $family_list = $font->css_family->value;
  }
  else {
    $family_list = "'" . $font->css_family->value . "'";
  }
  if ($font_style !== NULL) {
    if (!empty($font_style
      ->getFallback())) {
      $family_list .= ', ' . $font_style
        ->getFallback();
    }
  }
  $css[] = 'font-family: ' . $family_list . ';';
  $css[] = 'font-style: ' . $font->css_style->value . ';';
  $css[] = 'font-weight: ' . $font->css_weight->value . ';';
  return implode($separator, $css);
}