function availability_calendars_admin_settings_add_state in Availability Calendars 7.2
Same name and namespace in other branches
- 6.2 availability_calendars.admin.inc \availability_calendars_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 $element: The form element of which to add the state item.
int $i: The state item count.
array $state: Array containing a state record.
array $settings: Array containing general (i.e. non per state) settings.
1 call to availability_calendars_admin_settings_add_state()
- availability_calendars_admin_settings in ./
availability_calendars.admin.inc - Retrieve form callback for the admin/config/availability-calendars/settings page.
File
- ./
availability_calendars.admin.inc, line 170
Code
function availability_calendars_admin_settings_add_state(&$element, $i, $state, $settings) {
static $max_weight = 0;
$element[$i]['label'] = array(
'#type' => 'textfield',
'#title' => $i == 0 ? t('Label') : '',
'#default_value' => $state['label'],
'#size' => 40,
'#prefix' => '<div class="state-item">',
);
$element[$i]['css_class'] = array(
'#type' => 'textfield',
'#title' => $i == 0 ? t('CSS Class') : '',
'#default_value' => $state['css_class'],
'#size' => 24,
);
// Bit difficult to add a set of related radio button's that do not appear together.
$element[$i]['defaultstatus'] = array(
'#type' => 'radio',
'#tree' => FALSE,
'#title' => $i == 0 ? t('Default') : '',
'#title_display' => 'before',
'#return_value' => $i,
'#default_value' => !empty($state['css_class']) && $state['css_class'] == $settings->defaultstatus ? $i : 0,
// Use the name attribute to group the radio buttons scattered over the items/rows.
'#attributes' => array(
'name' => 'defaultstatus',
),
);
$element[$i]['is_available'] = array(
'#type' => 'checkbox',
'#title' => $i == 0 ? t('Is available?') : '',
'#title_display' => 'before',
'#default_value' => $state['is_available'],
);
$element[$i]['weight'] = array(
'#type' => 'select',
'#title' => $i == 0 ? t('Weight') : '',
'#default_value' => $state['weight'] > 0 ? $state['weight'] : ++$max_weight,
'#options' => array_combine(range(1, 20, 1), range(1, 20, 1)),
'#suffix' => '</div>',
);
if ($state['weight'] > $max_weight) {
$max_weight = $state['weight'];
}
}