You are here

function availability_calendar_admin_settings_add_state in Availability Calendars 7.5

Same name and namespace in other branches
  1. 7.3 availability_calendar.admin.inc \availability_calendar_admin_settings_add_state()
  2. 7.4 availability_calendar.admin.inc \availability_calendar_admin_settings_add_state()

Helper function to add a state item to a form. Only the first item gets labels, as the fields will be presented below each other.

Parameters

array $state: Array containing a state record.

Return value

array A form element with children only.

1 call to availability_calendar_admin_settings_add_state()
availability_calendar_admin_settings in ./availability_calendar.admin.inc
Defines form callback for the admin/config/availability-calendar/settings page.

File

./availability_calendar.admin.inc, line 127

Code

function availability_calendar_admin_settings_add_state($state) {
  static $max_weight = 0;
  $element = array();
  $element['sid'] = array(
    '#type' => 'hidden',
    '#value' => $state['sid'],
  );
  $element['label'] = array(
    '#type' => 'textfield',
    '#default_value' => $state['label'],
    '#size' => 40,
  );
  $element['css_class'] = array(
    '#type' => 'textfield',
    '#default_value' => $state['css_class'],
    '#size' => 24,
  );
  $element['is_available'] = array(
    '#type' => 'checkbox',
    '#title_display' => 'before',
    '#default_value' => $state['is_available'],
  );
  $element['weight'] = array(
    '#type' => 'weight',
    '#default_value' => $state['weight'] > 0 ? $state['weight'] : ++$max_weight,
    '#attributes' => array(
      'class' => array(
        'state-weight',
      ),
    ),
  );
  if ($state['weight'] > $max_weight) {
    $max_weight = $state['weight'];
  }
  return $element;
}