function availability_calendars_admin_settings_add_state in Availability Calendars 6.2
Same name and namespace in other branches
- 7.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 to add the state item to:
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/settings/availability-calendars/settings page.
File
- ./
availability_calendars.admin.inc, line 162
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' => 24,
'#prefix' => '<div class="state-item">',
);
$element[$i]['class'] = array(
'#type' => 'textfield',
'#title' => $i == 0 ? t('Class') : '',
'#default_value' => $state['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,
// Use our own label format (as with a radio button the label appears after the radio button)
// and wrap it in our own div.form-item
'#prefix' => $i == 0 ? '<div class="cal-state-label form-item"><label for="edit-defaultstatus">' . t('Default') . ': </label>' : '',
'#suffix' => $i == 0 ? '</div>' : '',
'#return_value' => $i,
'#default_value' => !empty($state['class']) && $state['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',
// Use our own label format (as with a radio button the label appears after the radio button)
// and wrap it in our own div.form-item
'#prefix' => $i == 0 ? '<div class="cal-state-label form-item"><label for="edit-defaultstatus">' . t('Is available?') . ': </label>' : '',
'#suffix' => $i == 0 ? '</div>' : '',
'#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'];
}
}