You are here

function cloud_zoom_admin_preset_edit_form in Cloud Zoom 6

The edit form callback - provides editable fields for all the "default" options

1 string reference to 'cloud_zoom_admin_preset_edit_form'
cloud_zoom_menu in ./cloud_zoom.module
Implementation of hook_menu().

File

./cloud_zoom.admin.inc, line 116
This file contains al the admin-only function

Code

function cloud_zoom_admin_preset_edit_form(&$form_state, $preset = NULL) {

  // Create a form with the preset key stored
  $form = array();
  $form['preset'] = array(
    '#tree' => TRUE,
  );
  if (isset($preset['name'])) {
    $form['#original_preset'] = $preset;
  }
  $form['preset']['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Preset Name'),
    '#description' => t('Enter the name for this preset. Only user lowercase alphanumeric values and hyphens.'),
    '#default_value' => isset($preset['name']) ? $preset['name'] : '',
    '#required' => TRUE,
  );
  if (isset($preset['storage']) && $preset['storage'] != CLOUD_ZOOM_STORAGE_NORMAL) {
    $form['preset']['name']['#type'] = 'item';
    $form['preset']['name']['#value'] = $form['preset']['name']['#default_value'];
  }

  // For every imagecache preset, create a presetname => presetname pair
  $imagecache_presets = array();
  foreach (imagecache_presets() as $id => $imagecache_preset) {
    $imagecache_presets[$imagecache_preset['presetname']] = $imagecache_preset['presetname'];
  }

  // Create a fieldset with options to set the view and zoom presets
  $form['preset']['imagecache_presets'] = array(
    '#type' => 'fieldset',
    '#title' => t('Imagecache Settings'),
    '#description' => t('Set the preview (zoomed out) and zoom Imagecache Presets below'),
  );
  $form['preset']['imagecache_presets']['view_preset'] = array(
    '#title' => t('View Preset'),
    '#description' => t('Set the Imagecache preset to use for the preview (ie the "zoomed out" view)'),
    '#type' => 'select',
    '#options' => $imagecache_presets,
    '#default_value' => isset($preset['view_preset']) ? $preset['view_preset'] : '',
    '#parents' => array(
      'preset',
      'view_preset',
    ),
  );
  $form['preset']['imagecache_presets']['zoom_preset'] = array(
    '#title' => t('Zoom Preset'),
    '#description' => t('Set the Imagecache preset to use for the zoomed in view'),
    '#type' => 'select',
    '#options' => $imagecache_presets,
    '#default_value' => isset($preset['zoom_preset']) ? $preset['zoom_preset'] : '',
    '#parents' => array(
      'preset',
      'zoom_preset',
    ),
  );

  // Create a settings fieldset with tree enabled
  $form['preset']['settings'] = array(
    '#type' => 'fieldset',
    '#title' => t('Settings'),
    '#theme' => 'cloud_zoom_admin_settings_table',
  );

  // Create a form element for every "default" setting to allow override
  $defaults = _cloud_zoom_default_settings();
  foreach ($defaults as $option => $values) {

    // The default value is either the overridden value or the default provided by _cloud_zoom_default_settings().
    $values['default'] = isset($preset['settings'][$option]) ? $preset['settings'][$option] : $values['default'];

    // Define the field settings based on the option - some are text, some are selects (for example)
    $field_settings = array();
    $field_prefix = $options = $type = $size = $maxlength = NULL;
    switch ($option) {
      case 'position':
        $field_settings['#size'] = 8;
        $field_settings['#maxlength'] = 48;
        break;
      case 'smoothMove':
        $field_settings['#size'] = $field_settings['#maxlength'] = 1;
        break;
      case 'adjustX':
      case 'adjustY':
        $field_settings['#field_suffix'] = 'px';
        break;
      case 'tint':
        $field_settings['#field_prefix'] = '#';
        $field_settings['#size'] = $field_settings['#maxlength'] = 6;
        break;
      case 'softFocus':
      case 'showTitle':
        $field_settings['#options'] = array(
          'false' => 'false',
          'true' => 'true',
        );
        $field_settings['#type'] = 'select';
        $field_settings['#size'] = 1;
        $field_settings['#maxlength'] = NULL;
        break;
    }

    // Create the option element based on the settings above
    $form['preset']['settings'][$option] = $field_settings + array(
      '#type' => 'textfield',
      '#title' => $option,
      '#description' => $values['description'],
      '#default_value' => $values['default'],
      '#size' => 4,
      '#maxlength' => 4,
    );
  }

  // We need at least a submit, with its own submit handler
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
    '#submit' => array(
      'cloud_zoom_admin_preset_edit_form_submit_save',
    ),
  );

  // TODO - add a reset IF it can be reset

  /*
  $form['reset'] = array(
    '#type' => 'submit',
    '#value' => t('Reset'),
    '#submit' => array('cloud_zoom_admin_preset_edit_form_submit_reset'),
  );
  */
  return $form;
}