You are here

function rooms_unit_type_form in Rooms - Drupal Booking for Hotels, B&Bs and Vacation Rentals 7

Generates the unit type editing form.

File

modules/rooms_unit/rooms_unit_type.admin.inc, line 32
RoomsUnit type editing UI.

Code

function rooms_unit_type_form($form, &$form_state, $unit_type, $op = 'edit') {
  $form['#attributes']['class'][] = 'rooms-management-form rooms-unit-type-edit-form';
  $form['#attached']['css'] = array(
    drupal_get_path('module', 'rooms_unit') . '/css/rooms_unit_type.css',
  );
  if ($op == 'clone') {
    $unit_type->label .= ' (cloned)';
    $unit_type->type = '';
  }
  $form['label'] = array(
    '#title' => t('Unit type name'),
    '#type' => 'textfield',
    '#default_value' => $unit_type->label,
    '#description' => t('The human-readable name of this unit type.'),
    '#required' => TRUE,
    '#size' => 30,
    '#weight' => -100,
  );

  // Machine-readable type name.
  $form['type'] = array(
    '#type' => 'machine_name',
    '#default_value' => isset($unit_type->type) ? $unit_type->type : '',
    '#maxlength' => 32,
    '#machine_name' => array(
      'exists' => 'rooms_unit_get_types',
      'source' => array(
        'label',
      ),
    ),
    '#description' => t('A unique machine-readable name for this unit type. It must only contain lowercase letters, numbers, and underscores.'),
    '#weight' => -99,
  );
  $form['unit_defaults'] = array(
    '#type' => 'fieldset',
    '#description' => '<strong>' . t('Unit defaults') . '</strong> - ' . t('Values specified below will be pre-populated as the defaults when creating units of this type.'),
    '#tree' => FALSE,
    '#weight' => -98,
    '#attributes' => array(
      'class' => array(
        'rooms-unit-type-defaults',
      ),
    ),
  );
  $form['unit_defaults']['data']['#tree'] = TRUE;
  $form['unit_defaults']['data']['base_price'] = array(
    '#type' => 'textfield',
    '#title' => t('Default base price'),
    '#default_value' => isset($unit_type->data['base_price']) ? $unit_type->data['base_price'] : '',
    '#size' => 5,
    '#field_suffix' => t('Per unit per night'),
    '#description' => t('The default base price is used for all units of this type and may be changed on the edit form of each unit individually.'),
    '#maxlength' => 10,
  );
  $form['unit_defaults']['guest_capacity'] = array(
    '#type' => 'fieldset',
    '#title' => t('Default sleeping capacity'),
    '#tree' => FALSE,
    '#attributes' => array(
      'class' => array(
        'rooms-unit-type-guest-capacity',
      ),
    ),
  );
  $form['unit_defaults']['guest_capacity']['data']['#tree'] = TRUE;
  $form['unit_defaults']['guest_capacity']['data']['min_sleeps'] = array(
    '#type' => 'textfield',
    '#size' => 5,
    '#default_value' => isset($unit_type->data['min_sleeps']) ? $unit_type->data['min_sleeps'] : '',
    '#field_suffix' => t('Person minimum'),
  );
  $form['unit_defaults']['guest_capacity']['data']['max_sleeps'] = array(
    '#type' => 'textfield',
    '#size' => 5,
    '#default_value' => isset($unit_type->data['max_sleeps']) ? $unit_type->data['max_sleeps'] : '',
    '#description' => t('The default number of guests (including adults and children) for each unit of this type.'),
    '#field_suffix' => t('Person maximum'),
  );
  $form['unit_defaults']['child_capacity'] = array(
    '#type' => 'fieldset',
    '#title' => t('Default child capacity'),
    '#tree' => FALSE,
    '#attributes' => array(
      'class' => array(
        'rooms-unit-type-child-capacity',
      ),
    ),
  );
  $form['unit_defaults']['child_capacity']['data']['#tree'] = TRUE;
  $form['unit_defaults']['child_capacity']['data']['min_children'] = array(
    '#type' => 'textfield',
    '#size' => 5,
    '#default_value' => isset($unit_type->data['min_children']) ? $unit_type->data['min_children'] : '',
    '#field_suffix' => t('Child minimum'),
  );
  $form['unit_defaults']['child_capacity']['data']['max_children'] = array(
    '#type' => 'textfield',
    '#size' => 5,
    '#default_value' => isset($unit_type->data['max_children']) ? $unit_type->data['max_children'] : '',
    '#description' => t('The default number of children per unit of this type.'),
    '#field_suffix' => t('Child maximum'),
  );
  $form['reference'] = array(
    '#type' => 'fieldset',
    '#tree' => FALSE,
    '#weight' => -97,
    '#attributes' => array(
      'class' => array(
        'rooms-unit-type-reference',
      ),
    ),
  );
  $form['reference']['data']['#tree'] = TRUE;
  $form['reference']['data']['rooms_description_source'] = array(
    '#type' => 'textfield',
    '#title' => t('Unit type description source'),
    '#description' => t('The node you choose here will be rendered in the booking results.'),
    '#size' => 30,
    '#maxlength' => 60,
    '#autocomplete_path' => 'admin/rooms/unit-type/description-source',
    '#default_value' => isset($unit_type->data['rooms_description_source']) ? $unit_type->data['rooms_description_source'] : '',
  );

  // Add the field related form elements.
  $form_state['rooms_unit_type'] = $unit_type;
  field_attach_form('rooms_unit_type', $unit_type, $form, $form_state);
  $form['additional_settings'] = array(
    '#type' => 'vertical_tabs',
    '#weight' => 99,
  );
  if (variable_get('rooms_booking_manager_type_selector', ROOMS_DISPLAY_TYPE_SELECTOR_NO)) {
    $unit_types = variable_get('rooms_unit_type_selector', array());
    $form['unit_type_selector'] = array(
      '#type' => 'checkbox',
      '#title' => t('Unit type selector'),
      '#description' => t('Unchecking this option the unit type will not appear in the unit-type selector form.'),
      '#options' => array(
        0 => 'Remove from unit type selector',
        1 => 'Add to unit type selector',
      ),
      '#default_value' => !empty($unit_types[$unit_type->type]),
      '#weight' => 100,
    );
  }
  $form['actions'] = array(
    '#type' => 'actions',
    '#tree' => FALSE,
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save unit type'),
    '#weight' => 100,
  );
  return $form;
}