You are here

function fontyourface_ui_apply_by_selector_form_submit in @font-your-face 7.2

Updates Fonts.

File

modules/fontyourface_ui/fontyourface_ui.module, line 968

Code

function fontyourface_ui_apply_by_selector_form_submit($form, &$form_state) {
  $updated = array();
  $selector_per_fid = array();
  $fallbacks_per_fid = array();
  foreach ($form_state['input']['fid'] as $old_fid => $new_fid) {
    $css_selector = $form_state['input']['css_selector'][$old_fid];
    $css_fallbacks = $form_state['input']['css_fallbacks'][$old_fid];
    $old_fid_int = intval($old_fid);
    $new_fid_int = intval($new_fid);
    if (!isset($selector_per_fid[$old_fid_int])) {
      $selector_per_fid[$old_fid_int] = array();
      $fallbacks_per_fid[$old_fid_int] = array();
    }

    // if
    if (!isset($selector_per_fid[$new_fid_int])) {
      $selector_per_fid[$new_fid_int] = array();
      $fallbacks_per_fid[$new_fid_int] = array();
    }

    // if
    $selector_per_fid[$new_fid_int][] = $css_selector;
    $fallbacks_per_fid[$new_fid_int][] = $css_fallbacks;
  }

  // foreach
  unset($selector_per_fid[0]);
  unset($fallbacks_per_fid[0]);
  foreach ($selector_per_fid as $fid => $selector) {
    $full_selectors = array_unique($selector);
    $font = fontyourface_get_font($fid);
    $full_selector = implode(', ', $full_selectors);
    if ($font && $font->css_selector != $full_selector) {
      fontyourface_set_css_selector($font, $full_selector);
      $updated[$full_selector] = $full_selector;
    }

    // if
  }

  // foreach
  foreach ($fallbacks_per_fid as $fid => $fallbacks) {
    $full_fallbacks = array_unique($fallbacks);
    $font = fontyourface_get_font($fid);
    $full_fallback = implode(', ', $full_fallbacks);
    if ($font && $font->css_fallbacks != $full_fallback) {
      fontyourface_set_css_fallbacks($font, $full_fallback);
    }

    // if
  }

  // foreach
  if (count($updated)) {
    drupal_set_message(t('Updated') . ' <i>' . implode('</i>, <i>', $updated) . '</i>.');
  }
  else {
    drupal_set_message(t('Submitted fonts contained no changes.'), 'warning');
  }

  // else
}