You are here

function fontyourface_admin_add_form in @font-your-face 6

Add form shows detail and enables a single font.

1 string reference to 'fontyourface_admin_add_form'
fontyourface_menu in ./fontyourface.module
Implements hook_menu().

File

./fontyourface.module, line 303

Code

function fontyourface_admin_add_form(&$form_state, $module_name, $group_path, $font_path) {
  $breadcrumb = drupal_get_breadcrumb();
  $breadcrumb[] = l('@font-your-face', 'admin/build/themes/fontyourface');
  $breadcrumb[] = l('Add', 'admin/build/themes/fontyourface/add');
  drupal_set_breadcrumb($breadcrumb);
  drupal_add_js(drupal_get_path('module', 'fontyourface') . '/js/add_form.js');
  $font = fontyourface_get_font_from_path($module_name, $group_path, $font_path);
  if (!$font) {
    $font_path = str_replace(array(
      ' ',
      '!',
    ), array(
      '+',
      '%21',
    ), $font_path);
    $group_path = str_replace(array(
      ' ',
      '!',
    ), array(
      '+',
      '%21',
    ), $group_path);
    $font = fontyourface_get_font_from_path($module_name, $group_path, $font_path);
  }

  // if
  if ($font) {
    $view = $module_name . '_fontyourface_view';
    $font_in_use = new stdClass();
    $font_in_use->name = $font['font name'];
    $font_in_use->group_name = $font['group'];
    $font_in_use->provider = $font['module'];
    $css_function = $font_in_use->provider . '_fontyourface_css';
    $font_css = $css_function($font_in_use);
    $form = array(
      'module' => array(
        '#type' => 'hidden',
        '#value' => $font['module'],
      ),
      'font' => array(
        '#type' => 'hidden',
        '#value' => $font['font name'],
      ),
      'group' => array(
        '#type' => 'hidden',
        '#value' => $font['group'],
      ),
      'font_title' => array(
        '#value' => '<h2>' . check_plain($font['font name']) . '</h2>',
      ),
    );
    $license_function = $font_in_use->provider . '_fontyourface_license';
    if (function_exists($license_function)) {
      $license = $license_function($font_in_use);
      if ($license) {
        if ($license['url']) {
          $license_markup = l($license['name'], $license['url'], array(
            'attributes' => array(
              'rel' => 'license',
            ),
          ));
        }
        else {
          $license_markup = check_plain($license['name']);
        }

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

      // if
    }

    // if
    $form += array(
      '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(
        '#value' => '<div class="fontyourface-view">' . $view($font['font'], variable_get('fontyourface_sample_text', 'The quick brown fox jumps over the lazy dog')) . '</div>',
      ),
      'css' => array(
        '#type' => 'textarea',
        '#title' => t('CSS selector'),
        '#default_value' => '',
        '#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. e.g. "body" or "h1, h2, h3, h4"'),
      ),
      'font-family' => array(
        '#value' => '<div>' . t('To apply in your own CSS, use:') . '</div><div><code>font-family: ' . check_plain($font_css['font-family']) . ';</code></div>',
      ),
      'buttons' => array(
        'submit' => array(
          '#type' => 'submit',
          '#value' => t('Add font'),
        ),
        'cancel' => array(
          '#type' => 'submit',
          '#value' => t('Cancel'),
        ),
      ),
    );
    return $form;
  }
  else {
    $form = array(
      'not_found' => array(
        '#value' => t('Font not found. Looking for: !font', array(
          '!font' => $font_path,
        )),
      ),
    );
    return $form;
  }

  // else
}