You are here

function fontyourface_ui_admin_edit_form in @font-your-face 7.2

Edit form changes a single font, including CSS selector and enabled status.

2 string references to 'fontyourface_ui_admin_edit_form'
fontyourface_ui_menu in modules/fontyourface_ui/fontyourface_ui.module
Implements hook_menu().
local_fonts_form_alter in modules/local_fonts/local_fonts.module
Implements hook_form_alter().

File

modules/fontyourface_ui/fontyourface_ui.module, line 1092

Code

function fontyourface_ui_admin_edit_form($form, &$form_state, $fid) {
  drupal_add_js(drupal_get_path('module', 'fontyourface_ui') . '/js/add_form.js');
  $font = fontyourface_get_font($fid);
  fontyourface_font_registry($font);
  $info_function = $font->provider . '_fontyourface_info';
  if (function_exists($info_function)) {
    $provider = $info_function();
  }

  // if
  $form = array(
    'fid' => array(
      '#type' => 'hidden',
      '#value' => $font->fid,
    ),
    'details' => array(
      '#type' => 'fieldset',
      '#title' => t('Details'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      'font' => array(
        '#markup' => '<div class="font">' . t('Font: !font', array(
          '!font' => l($font->name, $font->url),
        )) . '</div>',
      ),
      'provider' => array(
        '#markup' => '<div class="provider">' . t('Provider: !provider', array(
          '!provider' => l($provider['name'], $provider['url']),
        )) . '</div>',
      ),
      'tags' => array(
        '#title' => t('Tags'),
        '#type' => 'textfield',
        '#default_value' => implode(', ', $font->tags),
        '#autocomplete_path' => 'fontyourface/autocomplete/tag',
        '#maxlength' => 1024,
      ),
    ),
  );
  if ($font->foundry != '') {
    if ($font->foundry_url != '') {
      $foundry_markup = l($font->foundry, $font->foundry_url);
    }
    else {
      $foundry_markup = check_plain($font->foundry);
    }

    // else
    $form['details'] += array(
      'foundry' => array(
        '#markup' => '<div class="foundry">' . t('Foundry: !foundry', array(
          '!foundry' => $foundry_markup,
        )) . '</div>',
      ),
    );
  }

  // if
  if ($font->license != '') {
    if ($font->license_url != '') {
      $license_markup = l($font->license, $font->license_url, array(
        'attributes' => array(
          'rel' => 'license',
        ),
      ));
    }
    else {
      $license_markup = check_plain($font->license);
    }

    // else
    $form['details'] += array(
      'license' => array(
        '#markup' => '<div class="license">' . t('License: !license', array(
          '!license' => $license_markup,
        )) . '</div>',
      ),
    );
  }

  // if
  $view = '';
  $view_function = $font->provider . '_fontyourface_preview';
  if (function_exists($view_function)) {
    $view = $view_function($font, variable_get('fontyourface_sample_text', 'The quick brown fox jumps over the lazy dog'), 'all');
  }

  // if
  $form += array(
    'preview' => array(
      '#type' => 'fieldset',
      '#title' => t('Preview'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      'sample_text' => array(
        '#type' => 'textfield',
        '#title' => t('Sample text'),
        '#default_value' => variable_get('fontyourface_sample_text', 'The quick brown fox jumps over the lazy dog'),
        '#size' => 60,
      ),
      'font_view' => array(
        '#markup' => '<div class="fontyourface-view">' . $view . '</div>',
      ),
    ),
    'css' => array(
      '#type' => 'textarea',
      '#title' => t('CSS selector'),
      '#resizable' => FALSE,
      '#rows' => 3,
      '#default_value' => $font->css_selector,
      '#description' => t('Use commas to separate multiple selectors, just like you would in CSS.'),
    ),
  );
  if ($font->css_family != '') {
    $css_family = $font->css_family[0] == "'" ? check_plain($font->css_family) : "'" . check_plain($font->css_family) . "'";
    $instructions = '<div><code>font-family: ' . $css_family . ';';
    $instructions .= !empty($font->css_style) && $font->css_style != 'normal' ? '<br />font-style: ' . check_plain($font->css_style) . ';' : '';
    $instructions .= !empty($font->css_weight) && $font->css_weight != 'normal' && $font->css_weight != '400' ? '<br />font-weight: ' . check_plain($font->css_weight) . ';' : '';
    $instructions .= '</code></div>';
    $form += array(
      'font-family' => array(
        '#markup' => '<div>' . t('To apply in your own CSS, use:') . '</div>' . $instructions,
      ),
    );
  }

  // if
  $form += array(
    'enabled' => array(
      '#type' => 'checkbox',
      '#title' => t('Enabled'),
      '#default_value' => $font->enabled,
    ),
    'buttons' => array(
      'submit' => array(
        '#type' => 'submit',
        '#value' => t('Save font settings'),
      ),
      'cancel' => array(
        '#type' => 'submit',
        '#value' => t('Cancel changes'),
      ),
    ),
  );
  return $form;
}