You are here

function availability_calendar_field_widget_and_formatter_settings_form in Availability Calendars 7.3

Same name and namespace in other branches
  1. 7.5 availability_calendar.field.inc \availability_calendar_field_widget_and_formatter_settings_form()
  2. 7.4 availability_calendar.field.inc \availability_calendar_field_widget_and_formatter_settings_form()

Returns the common elements for the widget and formatter settings forms.

The widget and the formatter have almost all their settings in common. This method returns the form elements that are commmon to both.

Parameters

array $field: The field structure being configured.

array $instance: The instance structure being configured.

boolean $widget: Whether we are creating the form elements for the widget (true) or the formatter (false).

string $type: The widget or formatter type. Both use the same names: availability_calendar or availability_calendar_viewport.

array $settings: The current widget or formatter settings (to use for the default vaules).

2 calls to availability_calendar_field_widget_and_formatter_settings_form()
availability_calendar_field_formatter_settings_form in ./availability_calendar.field.inc
Implements hook_field_formatter_settings_form(). @link http://api.drupal.org/api/drupal/modules--field_ui--field_ui.api.php/fun...
availability_calendar_field_widget_settings_form in ./availability_calendar.field.inc
Implements hook_field_widget_settings_form @link http://api.drupal.org/api/drupal/modules--field_ui--field_ui.api.php/fun...

File

./availability_calendar.field.inc, line 318
Availability Calendar module. Defines an availability calendar field.

Code

function availability_calendar_field_widget_and_formatter_settings_form($field, $instance, $widget, $type, $settings) {
  $element = array();
  $element['show_number_of_months'] = array(
    '#type' => 'textfield',
    '#title' => t('Total number of months to @show', array(
      '@show' => $widget ? t('edit') : t('show'),
    )),
    '#default_value' => $settings['show_number_of_months'],
    '#required' => TRUE,
    '#element_validate' => array(
      '_element_validate_integer_positive',
    ),
  );
  if ($widget) {
    $element['show_number_of_months']['#description'] = t('The number of months to show when the calendar is being edited. Setting this larger than the number of months shown to normal visitors, allows editors to enter information into future calendar months before it is made publicly available.');
  }
  $element['first_day_of_week'] = array(
    '#type' => 'select',
    '#title' => t('First day of week'),
    '#default_value' => $settings['first_day_of_week'],
    // Use ISO-8601 week day numbers.
    '#options' => array(
      1 => t('Monday'),
      2 => t('Tuesday'),
      3 => t('Wednesday'),
      4 => t('Thursday'),
      5 => t('Friday'),
      6 => t('Saturday'),
      7 => t('Sunday'),
    ),
  );
  $element['show_week_number'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show the week number before each row of the calendar'),
    '#default_value' => $settings['show_week_number'],
  );
  $element['show_only_first_letter'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show only the first letter from the day of the week'),
    '#default_value' => $settings['show_only_first_letter'],
  );
  $element['show_split_day'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show split day states'),
    '#description' => t('Check this option if you want to show bookings from pm to am next morning.'),
    '#default_value' => $field['settings']['allocation_type'] === ALLOCATION_TYPE_OVERNIGHT && $settings['show_split_day'],
    '#access' => $field['settings']['allocation_type'] === ALLOCATION_TYPE_OVERNIGHT,
  );
  if (!$widget) {
    $element['selectable'] = array(
      '#type' => 'checkbox',
      '#title' => t('Interactive'),
      '#description' => t('Check this option if you want to let users interact with the calendar by clicking on available dates.'),
      '#default_value' => $settings['selectable'],
    );
  }
  if ($type == 'availability_calendar_viewport') {
    $element['viewport'] = array(
      '#type' => 'fieldset',
      '#tree' => TRUE,
      '#title' => t('Viewport settings'),
    );
    $element['viewport']['cols'] = array(
      '#type' => 'textfield',
      '#title' => t('Number of months to show horizontally'),
      '#default_value' => $settings['viewport']['cols'],
      '#required' => TRUE,
      '#element_validate' => array(
        '_element_validate_integer_positive',
      ),
    );
    $element['viewport']['rows'] = array(
      '#type' => 'textfield',
      '#title' => t('Number of months to show vertically'),
      '#default_value' => $settings['viewport']['rows'],
      '#required' => TRUE,
      '#element_validate' => array(
        '_element_validate_integer_positive',
      ),
    );
    $element['viewport']['scroll'] = array(
      '#type' => 'textfield',
      '#title' => t('Number of rows or cols to scroll'),
      '#description' => t('If the number of rows is 1, the viewport will scroll horizontally, otherwise it will scroll vertically.'),
      '#default_value' => $settings['viewport']['scroll'],
      '#required' => TRUE,
      '#element_validate' => array(
        '_element_validate_integer_positive',
      ),
    );
    $options = array(
      'before' => t('Before'),
      'after' => t('After'),
      'before_after' => t('1 Before and 1 after'),
      'not' => t('Not'),
    );
    $element['viewport']['button_placement'] = array(
      '#type' => 'select',
      '#title' => t('Button placement'),
      '#description' => t("Define where you want the have the buttons placed. If selecting '@not', you will have to define your own buttons.", array(
        '@not' => t('Not'),
      )),
      '#default_value' => $settings['viewport']['button_placement'],
      '#options' => $options,
      '#required' => TRUE,
    );
  }
  return $element;
}