You are here

function availability_calendar_field_widget_and_formatter_settings_form in Availability Calendars 7.5

Same name and namespace in other branches
  1. 7.3 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 common 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 values).

Return value

array

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 359

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.');
  }
  if ($type !== 'availability_calendar_ical') {
    $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'] === AC_ALLOCATION_TYPE_OVERNIGHT && $settings['show_split_day'],
      '#access' => $field['settings']['allocation_type'] === AC_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']['dimensions_calculation'] = array(
      '#type' => 'radios',
      '#title' => t('Which method to use to calculate the width (and height) of the viewport'),
      '#title_display' => 'before',
      '#options' => array(
        'none' => t('None'),
        'fixed' => t('Fixed'),
        'responsive_block' => t('Available width'),
        'responsive_inline' => t('Available width minus the width of the buttons'),
      ),
      'none' => array(
        '#description' => t('You should provide the width and height in custom CSS. The number of months to show horizontally and vertically are still needed to define the animations.'),
      ),
      'fixed' => array(
        '#description' => t('The width and height are based on the number of months to show horizontally and vertically.'),
      ),
      'responsive_block' => array(
        '#description' => t('Use this option in a responsive design where the next/previous buttons are placed above or below the viewport.'),
      ),
      'responsive_inline' => array(
        '#description' => t('Use this option in a responsive design where the next/previous buttons are placed inline with the viewport.'),
      ),
      '#default_value' => $settings['viewport']['dimensions_calculation'],
      '#required' => TRUE,
    );
    $name = $widget ? 'instance[widget][settings][viewport][dimensions_calculation]' : 'fields[' . $field['field_name'] . '][settings_edit_form][settings][viewport][dimensions_calculation]';
    $element['viewport']['cols'] = array(
      '#type' => 'textfield',
      '#title' => t('Number of months to show horizontally'),
      '#description' => t('The %responsive option overrules this setting.', array(
        '%responsive' => t('Responsive'),
      )),
      '#default_value' => $settings['viewport']['cols'],
      '#required' => $settings['viewport']['dimensions_calculation'] === 'none' || $settings['viewport']['dimensions_calculation'] === 'fixed',
      '#disabled' => $settings['viewport']['dimensions_calculation'] !== 'none' && $settings['viewport']['dimensions_calculation'] !== 'fixed',
      '#states' => array(
        'required' => array(
          ":input[name='{$name}']" => array(
            array(
              'value' => 'none',
            ),
            array(
              'value' => 'fixed',
            ),
          ),
        ),
        'enabled' => array(
          ":input[name='{$name}']" => array(
            array(
              'value' => 'none',
            ),
            array(
              'value' => 'fixed',
            ),
          ),
        ),
      ),
      '#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',
      ),
    );
    $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' => array(
        'before' => t('Before'),
        'after' => t('After'),
        'before_after' => t('1 Before and 1 after'),
        'not' => t('Not'),
      ),
      '#required' => TRUE,
    );
  }
  if ($type === 'availability_calendar_colorbox') {
    $element['colorbox'] = array(
      '#type' => 'fieldset',
      '#tree' => TRUE,
      '#title' => t('Colorbox settings'),
    );
    $element['colorbox']['width'] = array(
      '#type' => 'textfield',
      '#title' => t('Width of the colorbox'),
      '#default_value' => $settings['colorbox']['width'],
      '#required' => FALSE,
      '#element_validate' => array(
        'availability_calendar_field_widget_and_formatter_settings_form_validate_colorbox_width',
      ),
    );
    $element['colorbox']['height'] = array(
      '#type' => 'textfield',
      '#title' => t('Height of the colorbox'),
      '#default_value' => $settings['colorbox']['height'],
      '#required' => FALSE,
      '#element_validate' => array(
        'availability_calendar_field_widget_and_formatter_settings_form_validate_colorbox_height',
      ),
    );
  }
  return $element;
}