function fonts_com_enable_from_active_project in @font-your-face 7.2
Enables fonts locally based on the current active project.
2 calls to fonts_com_enable_from_active_project()
- fonts_com_import_finished in modules/
fonts_com/ fonts_com.module - Completes import.
- fonts_com_project_edit_form_submit in modules/
fonts_com/ fonts_com.module - Saves changes to project.
File
- modules/
fonts_com/ fonts_com.module, line 800
Code
function fonts_com_enable_from_active_project() {
module_load_include('inc', 'fonts_com', 'api');
// Disables all Fonts.com fonts.
db_update('fontyourface_font')
->fields(array(
'enabled' => 0,
))
->condition('provider', 'fonts_com')
->execute();
// Gets all fonts in active project.
$fids_to_enable = array();
$project_id = variable_get('fonts_com_project', '');
$selectors_by_font_id = array();
if ($project_id != '') {
$import_fonts = fonts_com_get_fonts_in_project($project_id);
foreach ($import_fonts as $import_font) {
$font = fonts_com_saved_api_font($import_font);
$fids_to_enable[] = intval($font->fid);
}
// foreach
$selectors = fonts_com_get_selectors_in_project($project_id);
foreach ($selectors as $selector) {
$selectors_by_font_id[$selector->SelectorFontID] = $selector->SelectorTag;
}
// foreach
}
// if
// Enables all fonts in active project.
if (count($fids_to_enable) > 0) {
$font_results = db_select('fontyourface_font', 'f')
->fields('f')
->condition('f.provider', 'fonts_com')
->condition('f.fid', $fids_to_enable, 'IN')
->execute();
foreach ($font_results as $font_result) {
/**
* Note: this relies on fonts_com_fontyourface_enable() saving the font
* to save the imported selector.
*/
$metadata = unserialize($font_result->metadata);
$font_id = $metadata['details']->FontID;
if (isset($selectors_by_font_id[$font_id])) {
$font_result->css_selector = $selectors_by_font_id[$font_id];
}
else {
$font_result->css_selector = '';
}
// else
fontyourface_enable_font($font_result);
}
// foreach
}
// if
}