You are here

function availability_calendar_booking_formlet_field_formatter_settings_form_inc in Availability Calendars 7.5

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

1 call to availability_calendar_booking_formlet_field_formatter_settings_form_inc()
availability_calendar_booking_formlet_field_formatter_settings_form in booking_formlet/availability_calendar_booking_formlet.module
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.inc, line 184
General helper methods for Availability Calendar Booking formlet to make the .module file smaller:

Code

function availability_calendar_booking_formlet_field_formatter_settings_form_inc($field, $instance, $view_mode) {
  $display = $instance['display'][$view_mode];
  $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, the user and this booking formlet. You should only check this option if the dates will be filled as per the settings below and you do not want the user to change the values anymore.'),
  );
  $element['single_day_only'] = array(
    '#type' => 'checkbox',
    '#title' => t('Only allow single day bookings'),
    '#default_value' => $settings['single_day_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['display_duration'] = array(
    '#type' => 'select',
    '#title' => t('Display number of days'),
    '#default_value' => $settings['display_duration'],
    '#options' => availability_calendar_booking_formlet_field_formatter_settings_form_get_options(),
    '#required' => FALSE,
  );
  $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;
}