You are here

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

Implements hook_field_widget_form().

File

./rooms.module, line 703
Provides basic underlying functionality and configuration options used by all Rooms modules

Code

function rooms_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
  if ($instance['widget']['type'] == 'rooms_options_combined') {
    $field_parents = $element['#field_parents'];
    $field_name = $element['#field_name'];
    $language = $element['#language'];
    $parents = array_merge($field_parents, array(
      $field_name,
      $language,
      $delta,
    ));
    $element['name'] = array(
      '#type' => 'textfield',
      '#title' => t('Name'),
      '#default_value' => isset($items[$delta]['name']) ? $items[$delta]['name'] : NULL,
      '#attributes' => array(
        'class' => array(
          'rooms-option--name',
        ),
      ),
    );
    $element['quantity'] = array(
      '#type' => 'select',
      '#title' => t('Quantity'),
      '#options' => rooms_assoc_range(1, 10),
      '#default_value' => isset($items[$delta]['quantity']) ? $items[$delta]['quantity'] : NULL,
      '#description' => t('How many of this option should be available'),
      '#attributes' => array(
        'class' => array(
          'rooms-option--quantity',
        ),
      ),
    );
    $price_options = rooms_price_options_options();
    $element['operation'] = array(
      '#type' => 'select',
      '#title' => t('Operation'),
      '#options' => $price_options,
      '#default_value' => isset($items[$delta]['operation']) ? $items[$delta]['operation'] : NULL,
      '#attributes' => array(
        'class' => array(
          'rooms-option--operation',
        ),
      ),
    );
    $element['value'] = array(
      '#type' => 'textfield',
      '#title' => t('Value'),
      '#size' => 10,
      '#default_value' => isset($items[$delta]['value']) ? $items[$delta]['value'] : NULL,
      '#element_validate' => array(
        'element_validate_number',
      ),
      '#attributes' => array(
        'class' => array(
          'rooms-option--value',
        ),
      ),
    );
    $type_options = array(
      ROOMS_OPTION_OPTIONAL => t('Optional'),
      ROOMS_OPTION_MANDATORY => t('Mandatory'),
      ROOMS_OPTION_ONREQUEST => t('On Request'),
    );
    $element['type'] = array(
      '#type' => 'select',
      '#title' => t('Type'),
      '#options' => $type_options,
      '#default_value' => isset($items[$delta]['type']) ? $items[$delta]['type'] : 'optional',
      '#attributes' => array(
        'class' => array(
          'rooms-option--type',
        ),
      ),
    );
    $element['remove'] = array(
      '#delta' => $delta,
      '#name' => implode('_', $parents) . '_remove_button',
      '#type' => 'submit',
      '#value' => t('Remove'),
      '#validate' => array(),
      '#submit' => array(
        'rooms_options_remove_submit',
      ),
      '#limit_validation_errors' => array(),
      '#ajax' => array(
        'path' => 'rooms_options/ajax',
        'effect' => 'fade',
      ),
      '#attributes' => array(
        'class' => array(
          'rooms-option--remove-button',
        ),
      ),
    );
    $element['#attached']['css'] = array(
      drupal_get_path('module', 'rooms') . '/css/rooms_options_widget.css',
    );
    return $element;
  }
}