function bat_event_states_form in Booking and Availability Management Tools for Drupal 7
Implements form that handles the definition of states for fixed state events.
1 string reference to 'bat_event_states_form'
- bat_event_menu in modules/
bat_event/ bat_event.module - Implements hook_menu().
File
- modules/
bat_event/ bat_event.module, line 382 - Manage Events - Events store the EventValue of a Unit over a period of time.
Code
function bat_event_states_form($form, &$form_state, $event_type) {
if ($event_type->fixed_event_states) {
$event_states = bat_event_get_states($event_type->type);
$header = array(
t('ID'),
t('Machine name'),
t('Label'),
t('Blocking'),
t('Operations'),
);
$default_state = 0;
$rows = array();
foreach ($event_states as $event_state) {
$operations = array();
$operations[] = array(
'title' => t('Edit'),
'href' => 'admin/bat/config/events/event/' . $event_state['id'] . '/edit',
);
if (!$event_state['locked']) {
$operations[] = array(
'title' => t('Delete'),
'href' => 'admin/bat/config/events/event/' . $event_state['id'] . '/delete',
);
}
$rows[] = array(
$event_state['id'],
$event_state['machine_name'],
$event_state['label'],
$event_state['blocking'],
theme('links', array(
'links' => $operations,
'attributes' => array(
'class' => array(
'links',
'inline',
),
),
)),
);
if ($event_state['default_state']) {
$default_state = count($rows) - 1;
}
}
if (!empty($rows)) {
$form['states'] = array(
'#type' => 'tableselect',
'#header' => $header,
'#options' => $rows,
'#multiple' => FALSE,
'#default_value' => $default_state,
'#prefix' => '<div id="event-state-wrapper">',
'#suffix' => '</div>',
);
$form['set_default'] = array(
'#type' => 'submit',
'#value' => t('Set default state'),
'#limit_validation_errors' => array(
array(
'states',
),
),
'#submit' => array(),
'#ajax' => array(
'callback' => 'bat_event_states_form_set_default',
'wrapper' => 'event-state-wrapper',
),
);
}
$form['new_state'] = array(
'#type' => 'fieldset',
'#title' => 'Create new state',
);
$form['event_type'] = array(
'#type' => 'hidden',
'#value' => $event_type->type,
);
$form['new_state']['label'] = array(
'#type' => 'textfield',
'#title' => t('Label'),
'#required' => TRUE,
);
$form['new_state']['machine_name'] = array(
'#type' => 'machine_name',
'#maxlength' => 32,
'#machine_name' => array(
'exists' => 'bat_event_load_state_by_machine_name',
'source' => array(
'new_state',
'label',
),
),
);
$form['new_state']['color'] = array(
'#type' => 'textfield',
'#title' => t('Color'),
'#size' => 12,
'#maxlength' => 7,
'#element_validate' => array(
'bat_event_validate_hex_color',
),
'#dependency' => array(
'edit-row-options-colors-legend' => array(
'type',
),
),
'#prefix' => '<div class="bat-colorpicker-wrapper form-wrapper">',
'#suffix' => '<div class="bat-colorpicker"></div></div>',
'#attributes' => array(
'class' => array(
'bat-edit-colorpicker',
),
),
'#attached' => array(
// Add Farbtastic color picker.
'library' => array(
array(
'system',
'farbtastic',
),
),
// Add javascript to trigger the colorpicker.
'js' => array(
drupal_get_path('module', 'bat_event') . '/js/bat_color.js',
),
),
'#required' => TRUE,
);
$form['new_state']['calendar_label'] = array(
'#type' => 'textfield',
'#title' => t('Calendar label'),
'#size' => 10,
'#maxlength' => 50,
'#required' => TRUE,
);
$form['new_state']['blocking'] = array(
'#type' => 'checkbox',
'#title' => t('Blocking'),
);
$form['new_state']['submit'] = array(
'#type' => 'submit',
'#value' => t('Add state'),
);
}
else {
$form['empty'] = array(
'#markup' => t('This event type cannot define fixed states!'),
);
}
return $form;
}