You are here

function google_fonts_update_6100 in Google Fonts 6.2

Change the google_fonts array of enabled fonts to the new format

File

./google_fonts.install, line 24
Installation file for Google Fonts module.

Code

function google_fonts_update_6100() {
  $ret = array();
  if ($all_fonts = _google_fonts_available_fonts(TRUE)) {
    $enabled_fonts = variable_get('google_fonts_enabled_fonts', array());
    $enabled = array();
    if (!empty($all_fonts) && !empty($enabled_fonts)) {
      foreach ($all_fonts as $font) {
        foreach ($font->variants as $variant) {
          $key = $variant == 'regular' ? $font->family : $font->family . ' ' . $variant;
          if (!empty($enabled_fonts[$key]) && empty($enabled[$array_key])) {
            $array_key = _google_fonts_family_array_key_encode($font->family, $variant);
            $enabled[$array_key] = array(
              'family' => $font->family,
              'subsets' => in_array('latin', $font->variants) ? array(
                'latin' => 'latin',
              ) : array_shift($font->variants),
              'variants' => array(
                $variant => $variant,
              ),
            );
          }
        }
      }
    }
    db_query("DELETE FROM {variable} WHERE name LIKE '%s'", 'google_fonts_ui_%');

    // Overwrite the old format with the new format
    variable_set('google_fonts_enabled_fonts', $enabled);
    return $ret;
  }
  else {
    return array(
      array(
        'success' => FALSE,
        'query' => t("There seems to be a problem to connect to the Google API. Please check your connection and try again."),
      ),
    );
  }
}