You are here

function boolean_field_instance_settings_form in Boolean Field 7

Implements hook_field_instance_settings_form().

Initially build the form without the vertical tabs so that the instance settings form items are parented like instance[settings][true][prefix]. If we try to build it all at once, then the parenting is nested two more levels like instance[settings][state][tabs][true][prefix] and does not line up with the instance settings as defined in the hook_field_info().

Then use an #after_build handler to insert the fieldset and vertical tabs.

File

./boolean.module, line 71
Defines boolean field type.

Code

function boolean_field_instance_settings_form($field, $instance) {
  $settings = $instance['settings'];
  $defaults = boolean_field_info();
  $defaults = $defaults['number_boolean']['instance_settings'];
  $settings += $defaults;
  $form['labels'] = array(
    '#type' => 'textarea',
    '#title' => t('Labels'),
    '#default_value' => $settings['labels'],
    '#cols' => 20,
    '#description' => t("The labels to use in place of 'delta' in the display strings and on edit form. Enter one value per line. Only applies if cardinality is not unlimited."),
  );
  $form['suppress_warning'] = array(
    '#type' => 'checkbox',
    '#title' => t('Omit warning'),
    '#default_value' => $settings['suppress_warning'],
    '#description' => t("Omit the 'value not set' warning for unset fields."),
  );
  $form['omit_strings'] = array(
    '#type' => 'checkbox',
    '#title' => t('Omit strings'),
    '#default_value' => $settings['omit_strings'],
    '#description' => t('Omit the prefix and suffix strings on edit form.'),
  );
  foreach (boolean_value_info() as $state) {
    $form[$state] = array(
      '#type' => 'fieldset',
      '#title' => 'Strings to display when value is ' . $state,
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#tree' => TRUE,
      '#weight' => 5,
    );
    $form[$state]['prefix'] = array(
      '#type' => 'textfield',
      '#title' => t('Prefix'),
      '#default_value' => $settings[$state]['prefix'],
      '#size' => 60,
      '#description' => t("The string to be prefixed to the 'delta' value. Leave blank for none."),
    );
    $form[$state]['suffix'] = array(
      '#type' => 'textfield',
      '#title' => t('Suffix'),
      '#default_value' => $settings[$state]['suffix'],
      '#size' => 60,
      '#description' => t("The string to be suffixed to the 'delta' value. Leave blank for none."),
    );
  }
  $form['#after_build'][] = 'boolean_field_instance_settings_form_after_build';
  return $form;
}