You are here

function fontyourface_admin_edit_form in @font-your-face 7

Same name and namespace in other branches
  1. 6.2 fontyourface.module \fontyourface_admin_edit_form()
  2. 6 fontyourface.module \fontyourface_admin_edit_form()

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

2 string references to 'fontyourface_admin_edit_form'
fontyourface_menu in ./fontyourface.module
Implements hook_menu().
local_fonts_form_alter in modules/local_fonts/local_fonts.module
Implements hook_form_alter().

File

./fontyourface.module, line 581

Code

function fontyourface_admin_edit_form($form, &$form_state, $fid) {
  drupal_add_js(drupal_get_path('module', 'fontyourface') . '/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(
        '#value' => '<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(
        '#value' => '<div class="license">' . t('License: !license', array(
          '!license' => $license_markup,
        )) . '</div>',
      ),
    );
  }

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

  // 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. Leave blank to handle application of the font in your theme.'),
    ),
  );
  if ($font->css_family != '') {
    $form += array(
      'font-family' => array(
        '#value' => '<div>' . t('To apply in your own CSS, use:') . '</div><div><code>font-family: ' . check_plain($font->css_family) . ';</code></div>',
      ),
    );
  }

  // 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;
}