You are here

function textimage_form_settings in Textimage 7.3

Textimage settings form.

1 string reference to 'textimage_form_settings'
textimage_menu in ./textimage.module
Implements hook_menu().

File

./textimage.admin.inc, line 56
Textimage - Admin page callbacks.

Code

function textimage_form_settings($form, &$form_state) {

  // Main Textimage store location.
  $scheme_options = array();
  foreach (file_get_stream_wrappers(STREAM_WRAPPERS_WRITE_VISIBLE) as $scheme => $stream_wrapper) {
    $scheme_options[$scheme] = $stream_wrapper['name'];
  }
  $default_scheme = _textimage_get_variable('store_scheme');
  $default_scheme = isset($scheme_options[$default_scheme]) ? $default_scheme : 'public';
  $form['textimage_store'] = array(
    '#type' => 'fieldset',
    '#title' => t('Textimage store location'),
  );
  $form['textimage_store']['store_scheme'] = array(
    '#type' => 'radios',
    '#options' => $scheme_options,
    '#title' => t('Scheme'),
    '#description' => t('Select where the main Textimage file structure should be stored. It is recommended to keep it in the <strong>private</strong> file storage area.'),
    '#default_value' => $default_scheme,
  );

  // Fonts handler.
  $fonts_handling_module_options = array();
  $fonts_handling_module_options['textimage'] = t('Textimage');
  if (_textimage_module_exists('fontyourface', TEXTIMAGE_FONTYOURFACE_MIN_VERSION)) {
    $fonts_handling_module_options['fontyourface'] = t('@font-your-face');
  }
  $fonts_handling_module_selected = isset($form_state['values']['fonts_handling_module']) ? $form_state['values']['fonts_handling_module'] : _textimage_get_variable('fonts_handling_module');
  $default_font = _textimage_get_variable('default_font');

  // Fonts list.
  $fonts_list_options = array();
  if ($fonts_handling_module_selected == 'textimage') {
    $fonts_list_options['fonts_path'] = isset($form_state['values']['fonts_path']) ? $form_state['values']['fonts_path'] : _textimage_get_variable('fonts_path');
  }
  $fonts_list = TextimageFonts::getList($fonts_handling_module_selected, $fonts_list_options);
  if (!$fonts_list) {
    _textimage_diag(t('No fonts available. Make sure at least one font is installed, and select a default font for Textimage to use.'), WATCHDOG_WARNING);
  }
  $fonts_options = array();
  if (empty($fonts_list) or ($default_font['name'] == '' or !TextimageFonts::getUri($default_font['name']))) {
    $fonts_options[''] = t('- none -');
  }
  $fonts_options += drupal_map_assoc($fonts_list);

  // Fonts.
  $form['fonts'] = array(
    '#type' => 'fieldset',
    '#title' => t('Fonts'),
    '#description' => t('Number of fonts available: @fonts', array(
      '@fonts' => count($fonts_list),
    )),
    '#prefix' => '<div id="wrapper-fonts">',
    '#suffix' => '</div>',
  );
  $form['fonts']['fonts_handling_module'] = array(
    '#type' => 'select',
    '#title' => t('Fonts handling module'),
    '#options' => $fonts_handling_module_options,
    '#default_value' => $fonts_handling_module_selected,
    '#description' => t('Select the module Textimage has to use to manage fonts. If <a href="!path">@font-your-face</a> is installed and selected, Textimage will allow selection of enabled <em>local</em> fonts.', array(
      '!path' => url('http://drupal.org/project/fontyourface'),
    )),
    '#required' => TRUE,
    '#ajax' => array(
      'callback' => 'textimage_form_settings_ajax',
      'wrapper' => 'wrapper-fonts',
    ),
  );
  $form['fonts']['fonts_path'] = array(
    '#type' => 'textfield',
    '#title' => t('Path'),
    '#default_value' => _textimage_get_variable('fonts_path'),
    '#maxlength' => 255,
    '#description' => t('Location of the directory where the fonts are stored.'),
    '#states' => array(
      'visible' => array(
        ':input[name="fonts_handling_module"]' => array(
          'value' => 'textimage',
        ),
      ),
    ),
    '#ajax' => array(
      'callback' => 'textimage_form_settings_ajax',
      'wrapper' => 'wrapper-fonts',
    ),
  );
  $form['fonts']['default_font_name'] = array(
    '#type' => 'select',
    '#title' => t('Default font'),
    '#options' => $fonts_options,
    '#default_value' => $default_font['name'],
    '#description' => t('Select the default font to be used by Textimage.'),
    '#required' => TRUE,
  );

  // Background images.
  $backgrounds_handling_module_options = array();
  $backgrounds_handling_module_options['textimage'] = t('Textimage');
  if (_textimage_module_exists('media', TEXTIMAGE_MEDIA_MIN_VERSION)) {
    $backgrounds_handling_module_options['media'] = t('Media');
  }
  $backgrounds_handling_module_option_selected = isset($form_state['values']['backgrounds_handling_module']) ? $form_state['values']['backgrounds_handling_module'] : _textimage_get_variable('backgrounds_handling_module');
  $form['images'] = array(
    '#type' => 'fieldset',
    '#title' => t('Background images'),
  );
  $form['images']['backgrounds_handling_module'] = array(
    '#type' => 'select',
    '#title' => t('Backgrounds handling module'),
    '#options' => $backgrounds_handling_module_options,
    '#default_value' => $backgrounds_handling_module_option_selected,
    '#description' => t('Select the module Textimage has to use to manage background images. If <a href="!path">Media</a> is installed and selected, Textimage will use the Media browser to select images.', array(
      '!path' => url('http://drupal.org/project/media'),
    )),
    '#required' => TRUE,
  );
  $form['images']['backgrounds_path'] = array(
    '#type' => 'textfield',
    '#title' => t('Path'),
    '#default_value' => _textimage_get_variable('backgrounds_path'),
    '#maxlength' => 255,
    '#description' => t('Location of the directory where the background images are stored.') . ' ' . t('Relative paths will be resolved relative to the Drupal installation directory.'),
    '#states' => array(
      'visible' => array(
        ':input[name="backgrounds_handling_module"]' => array(
          'value' => 'textimage',
        ),
      ),
    ),
  );

  // Color selector.
  $color_selector_options = array();
  $color_selector_options['textbox'] = t('Textbox');
  if (_textimage_module_exists('jquery_colorpicker', TEXTIMAGE_JQUERY_COLORPICKER_MIN_VERSION)) {
    $color_selector_options['jquery_colorpicker'] = t('jQuery Colorpicker');
  }
  $form['color'] = array(
    '#type' => 'fieldset',
    '#title' => t('Colors'),
  );
  $form['color']['color_selector'] = array(
    '#type' => 'select',
    '#title' => t('Color selector'),
    '#options' => $color_selector_options,
    '#default_value' => _textimage_get_variable('color_selector'),
    '#description' => t('Select how colors should be input in administration forms. If <a href="!path">jQuery Colorpicker</a> is installed and selected, it provides a better alternative to mere hex code entry in a textbox.', array(
      '!path' => url('http://drupal.org/project/jquery_colorpicker'),
    )),
    '#required' => TRUE,
  );

  // Maintenance.
  $form['maintenance'] = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#title' => t('Maintenance'),
  );
  $form['maintenance']['flush_all'] = array(
    '#type' => 'submit',
    '#name' => 'flush_all',
    '#value' => t('Cleanup Textimage'),
  );

  // Save configuration.
  $form['save'] = array(
    '#type' => 'submit',
    '#name' => 'save',
    '#value' => t('Save configuration'),
  );
  return $form;
}