You are here

function formdefaults_edit_field in Form Defaults 5.3

Same name and namespace in other branches
  1. 6.2 formdefaults.admin.inc \formdefaults_edit_field()
  2. 7 formdefaults.admin.inc \formdefaults_edit_field()

Form to edit the field title and description.

1 string reference to 'formdefaults_edit_field'
formdefaults_edit in ./formdefaults.module
Edit form defaults

File

./formdefaults.admin.inc, line 314

Code

function formdefaults_edit_field() {
  $form_array = $_SESSION['formdefaults_forms'];
  $formid = arg(1);
  $fieldname = arg(2);
  drupal_set_title(t('Edit field @fieldname in @formid', array(
    '@fieldname' => $fieldname,
    '@formid' => $formid,
  )));
  $originalfields = $form_array[$formid][$fieldname] ? $form_array[$formid][$fieldname] : array();
  $savedform = formdefaults_getform($formid);
  $weight_range = range(-10, 10);
  $weights = array(
    'unset' => 'unset',
  );
  foreach ($weight_range as $weight) {
    $weights[(string) $weight] = (string) $weight;
  }
  if (is_array($savedform[$fieldname])) {
    $formfields = array_merge($originalfields, $savedform[$fieldname]);
  }
  else {
    $formfields = $originalfields;
  }
  $type = $formfields['type'];
  if (!$type) {
    if ($formfields['format']) {
      $type = 'markup';
    }
  }
  if ($originalfields['type']) {
    $type = $originalfields['type'];
  }
  $form['formid'] = array(
    '#type' => 'value',
    '#value' => $formid,
  );
  $form['fieldname'] = array(
    '#type' => 'value',
    '#value' => $fieldname,
  );
  $form['type'] = array(
    '#type' => 'value',
    '#title' => 'Field Type',
    '#value' => $type,
  );
  $form['warning'] = array(
    '#type' => 'markup',
    '#value' => 'Some text to edit',
  );
  $form['hide_it'] = array(
    '#type' => 'checkbox',
    '#title' => 'Hide this field',
    '#description' => 'Checking this box will convert the field to a hidden field.' . ' You will need to use the edit form link to unhide them. ',
    '#default_value' => $formfields['hide_it'],
  );
  if ($type == 'markup') {
    $form['value'] = array(
      '#type' => 'textarea',
      '#title' => 'Text or markup',
      '#rows' => 30,
      '#cols' => 80,
      '#default_value' => $formfields['value'],
    );
    $form['format'] = filter_form($formfields['format']);
    $form['value_original'] = array(
      '#type' => item,
      '#title' => 'Original value',
      '#value' => $originalfields['value'],
    );
  }
  else {
    $form['title'] = array(
      '#type' => 'textfield',
      '#title' => 'Field Title',
      '#default_value' => $formfields['title'],
    );
    $form['title_old'] = array(
      '#type' => 'item',
      '#title' => 'Original Title',
      '#value' => $originalfields['title'],
    );
    $form['description'] = array(
      '#type' => 'textarea',
      '#title' => 'Field Description',
      '#default_value' => $formfields['description'],
      '#rows' => 30,
      '#cols' => 80,
    );
    $form['description_old'] = array(
      '#type' => 'item',
      '#title' => 'Original Description',
      '#value' => $originalfields['description'],
    );
  }
  if ($type == 'fieldset') {
    $truefalse = array(
      '' => 'Leave alone',
      TRUE => 'Yes',
      FALSE => 'No',
    );
    $form['collapsible'] = array(
      '#type' => 'radios',
      '#title' => 'Collapsible',
      '#options' => $truefalse,
      '#default_value' => $formfields['collapsible'],
    );
    $form['collapsed'] = array(
      '#type' => 'radios',
      '#title' => 'Collapsed',
      '#options' => $truefalse,
      '#default_value' => $formfields['collapsed'],
    );
  }
  $form['weight'] = array(
    '#type' => 'select',
    '#title' => 'Weight',
    '#options' => $weights,
    '#default_value' => $formfields['weight'],
    '#description' => 'Higher values appear near at the top of the form, lower values at the bottom.',
  );
  $form['weight_old'] = array(
    '#type' => 'item',
    '#title' => 'Original Weight',
    '#value' => $originalfields['weight'],
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Save',
  );
  $form['reset'] = array(
    '#type' => 'submit',
    '#value' => 'Reset',
  );
  return $form;
}