You are here

function bat_unit_bundle_form in Booking and Availability Management Tools for Drupal 7

Generates the unit bundle editing form.

File

modules/bat_unit/bat_unit_bundle.admin.inc, line 34
BatUnitBundle editing UI.

Code

function bat_unit_bundle_form($form, &$form_state, $unit_bundle, $op = 'edit') {
  $form['#attributes']['class'][] = 'bat-management-form bat-unit-bundle-edit-form';
  if ($op == 'clone') {
    $unit_bundle->label .= ' (cloned)';
    $unit_bundle->type = '';
  }
  $form['label'] = array(
    '#title' => t('Unit bundle name'),
    '#type' => 'textfield',
    '#default_value' => $unit_bundle->label,
    '#description' => t('The human-readable name of this unit bundle.'),
    '#required' => TRUE,
    '#size' => 30,
    '#weight' => -100,
  );

  // Machine-readable type name.
  $form['type'] = array(
    '#type' => 'machine_name',
    '#default_value' => isset($unit_bundle->type) ? $unit_bundle->type : '',
    '#maxlength' => 32,
    '#machine_name' => array(
      'exists' => 'bat_unit_get_bundles',
      'source' => array(
        'label',
      ),
    ),
    '#description' => t('A unique machine-readable name for this unit bundle. It must only contain lowercase letters, numbers, and underscores.'),
    '#weight' => -99,
  );
  if ($op == 'edit') {
    $form['type']['#disabled'] = TRUE;
  }

  // Add the field related form elements.
  $form_state['bat_unit_bundle'] = $unit_bundle;
  field_attach_form('bat_unit_bundle', $unit_bundle, $form, $form_state);
  $form['additional_settings'] = array(
    '#type' => 'vertical_tabs',
    '#weight' => 99,
  );
  $form['actions'] = array(
    '#type' => 'actions',
    '#tree' => FALSE,
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save unit bundle'),
    '#weight' => 100,
    '#submit' => array(
      'bat_unit_bundle_form_submit',
    ),
  );
  return $form;
}