You are here

function availability_calendar_booking_formlet_field_formatter_settings_form in Availability Calendars 7.3

Same name and namespace in other branches
  1. 7.5 booking_formlet/availability_calendar_booking_formlet.module \availability_calendar_booking_formlet_field_formatter_settings_form()
  2. 7.4 booking_formlet/availability_calendar_booking_formlet.module \availability_calendar_booking_formlet_field_formatter_settings_form()

Implements hook_field_formatter_settings_form(). @link http://api.drupal.org/api/drupal/modules--field_ui--field_ui.api.php/fun...

File

booking_formlet/availability_calendar_booking_formlet.module, line 235
Availability Calendar booking formlet module. This submdule of the Availability Calendar module defines a field that shows a small booking form that interacts with a calendar field. The form only has an arraival and departure date field and a submit…

Code

function availability_calendar_booking_formlet_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
  $element = array();
  $display = $instance['display'][$view_mode];
  $type = $display['type'];
  $settings = $display['settings'];
  $name_prefix = 'fields[' . $field['field_name'] . '][settings_edit_form][settings]';
  $element = array();
  $element['submit_only'] = array(
    '#type' => 'checkbox',
    '#title' => t('Only show the "Book now" button'),
    '#default_value' => $settings['submit_only'],
    '#description' => t('This will hide the date fields and their reset buttons, effectively disabling any interaction between the calendar, user and this booking formlet. You should only check this option if the dates will be prefilled as per the settings below and you do not want the user to change that selection anymore.'),
  );
  $element['single_day_only'] = array(
    '#type' => 'checkbox',
    '#title' => t('Only allow single day bookings'),
    '#default_value' => $settings['submit_only'],
    '#description' => t('This will hide the departure date field, turning the form into a single day booking formlet. You should check this option if you only accept single day bookings and want to optimize the UI for that.'),
  );
  $element['description'] = array(
    '#type' => 'item',
    '#description' => t('Below you can specify default values for the begin and end date. These can come from dynamic sources like $_GET or $_POST and may contain angle brackets ("[" and "]") to access an array value. Note that these values will only be set if an accompanying calendar is indeed "available". This option will typically be used in combination with a "view" that filters on availability.'),
  );
  $element['preset_begin_date_source'] = array(
    '#type' => 'select',
    '#title' => t('Source for the begin date'),
    '#default_value' => $settings['preset_begin_date_source'],
    '#options' => array(
      'none' => t('None'),
      'today' => t('Today'),
      'get' => t('GET value'),
      'post' => t('POST value'),
    ),
    '#required' => FALSE,
  );
  $name_begin = $name_prefix . '[preset_begin_date_source]';
  $element['preset_begin_date_key'] = array(
    '#type' => 'textfield',
    '#title' => t('Key for the begin date value'),
    '#default_value' => $settings['preset_begin_date_key'],
    '#required' => $settings['preset_begin_date_source'] === 'get' || $settings['preset_begin_date_source'] === 'post',
    '#size' => 36,
    '#states' => array(
      'visible' => array(
        ":input[name='{$name_begin}']" => array(
          array(
            'value' => 'get',
          ),
          array(
            'value' => 'post',
          ),
        ),
      ),
      'required' => array(
        ":input[name='{$name_begin}']" => array(
          array(
            'value' => 'get',
          ),
          array(
            'value' => 'post',
          ),
        ),
      ),
    ),
  );
  $element['preset_end_date_source'] = array(
    '#type' => 'select',
    '#title' => t('Source for the end date'),
    '#default_value' => isset($settings['preset_end_date_source']) ? $settings['preset_end_date_source'] : 'none',
    '#options' => array(
      'none' => t('None'),
      'today' => t('Today'),
      'fixed_duration' => t('Fixed duration'),
      'get' => t('GET value as end date'),
      'post' => t('POST value as end date'),
      'get1' => t('GET value as departure date'),
      'post1' => t('POST value as departure date'),
      'get_duration' => t('GET value as duration'),
      'post_duration' => t('POST value as duration'),
    ),
    '#states' => array(
      'invisible' => array(
        ":input[name='{$name_begin}']" => array(
          'value' => 'none',
        ),
      ),
    ),
  );
  $name_end = $name_prefix . '[preset_end_date_source]';
  $element['preset_end_date_key'] = array(
    '#type' => 'textfield',
    '#title' => t('Key for the end date value or number of days'),
    '#default_value' => isset($settings['preset_end_date_key']) ? $settings['preset_end_date_key'] : '',
    '#required' => $settings['preset_end_date_source'] !== 'none' && $settings['preset_end_date_source'] !== 'today',
    '#size' => 36,
    '#states' => array(
      'invisible' => array(
        array(
          ":input[name='{$name_begin}']" => array(
            'value' => 'none',
          ),
        ),
        array(
          ":input[name='{$name_end}']" => array(
            array(
              'value' => 'none',
            ),
            array(
              'value' => 'today',
            ),
          ),
        ),
      ),
      'optional' => array(
        ":input[name='{$name_end}']" => array(
          array(
            'value' => 'none',
          ),
          array(
            'value' => 'today',
          ),
        ),
      ),
    ),
  );
  $element['#attached']['css'] = array(
    drupal_get_path('module', 'availability_calendar_booking_formlet') . '/availability_calendar_booking_formlet.admin.css',
  );
  return $element;
}