You are here

function google_fonts_update_7100 in Google Fonts 7.2

Same name and namespace in other branches
  1. 7 google_fonts.install \google_fonts_update_7100()

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_7100() {
  $ret = array();
  if ($all_fonts = _google_fonts_available_fonts()) {
    $enabled_fonts = variable_get('google_fonts_enabled_fonts', array());
    $enabled = array();
    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 :name', array(
      ':name' => '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."),
      ),
    );
  }
}