function calendar_form_alter
Search API
7.x calendar.module | calendar_form_alter(&$form, $form_id) |
6.x calendar.module | calendar_form_alter(&$form, $form_id) |
Implements hook_form_alter
We want to make various modifications to our form, based on what we are trying to do to it. We may also want to add in some custom javascript as well.
File
- modules/
calendar/ calendar.module, line 3181
Code
function calendar_form_alter(&$form, $form_id) {
global $user;
if ($form_id == 'content_edit_content_form') {
if (@$form ['type']['value'] == 'appointment') {
$db = get_global_database_handler();
$form ['#validate_handlers'][] = 'calendar_appointment_content_form_validate';
// If this is a NEW form, then check for values in the URL to auto-fill.
if ($form ['cid']['value'] === 'new') {
if (isset($_GET ['student_id'])) {
$form ['student_id']['value'] = $_GET ['student_id'];
$form ['student_id']['attributes'] = array('class' => 'hidden');
$form ['mark_to'] = array(
'type' => 'markup',
'value' => "<div class='appointment-field-mark appointment-student'><label>" . t("To") . ":</label>
" . $db->get_student_name($form ['student_id']['value'], TRUE) . "
</div>",
'weight' => $form ['student_id']['weight'],
);
}
if (isset($_GET ['faculty_id'])) {
$form ['faculty_id']['value'] = $_GET ['faculty_id'];
$form ['faculty_id']['attributes'] = array('class' => 'hidden');
$form ['mark_from'] = array(
'type' => 'markup',
'value' => "<div class='appointment-field-mark calendar-faculty_id'><label>" . t("Faculty/Staff") . ":</label>
" . $db->get_faculty_name($form ['faculty_id']['value']) . "
</div>",
'weight' => $form ['faculty_id']['weight'],
);
}
// Set the date/time to NOW (since this is new).
$form ['appointment_datetime']['value'] = date('Y-m-d\TH:i', convert_time(time()));
// If _GET['date'] is set, then we will set the appointment date to THAT + the current time.
// We pass it through strtotime to help sanitize.
if (isset($_GET ['date']) && $_GET ['date'] != '') {
$form ['appointment_datetime']['value'] = date('Y-m-d', strtotime($_GET ['date'])) . date('\TH:i', convert_time(time()));
}
// Always set the published = TRUE, and hide.
$form ['published']['value'] = TRUE;
$form ['published']['attributes'] = array('class' => 'hidden');
// If this user has Zoom set up, then show an option to make this a zoom meeting.
$test = FALSE;
if (module_enabled("zoomapi")) {
$test = zoomapi_get_zoomapi_data_for_user($user->id);
}
if ($test) {
$form ['enable_zoom'] = array(
'type' => 'checkbox',
'label' => t("Make this a Zoom video meeting?"),
'description' => t("Check this box if this is a Zoom video meeting. A Zoom meeting will be created automatically
and the recipients will be notified."),
'weight' => 5,
);
}
} // cid == new
} // form type == appointment
if (@$form ['type']['value'] == 'schedule_event_type') {
if ($form ['cid']['value'] === 'new') {
$db = get_global_database_handler();
if (isset($_GET ['faculty_id'])) {
$form ['faculty_id']['value'] = $_GET ['faculty_id'];
}
} // new
// Always set the published = TRUE, and hide.
$form ['published']['value'] = TRUE;
$form ['published']['attributes'] = array('class' => 'hidden');
// Always hide faculty_id field.
$form ['faculty_id']['attributes'] = array('class' => 'hidden');
$form ['mark_from'] = array(
'type' => 'markup',
'value' => "<div class='appointment-field-mark calendar-faculty_id'><label>" . t("Faculty/Staff") . ":</label>
" . fp_get_faculty_name($form ['faculty_id']['value']) . "
</div>",
'weight' => $form ['faculty_id']['weight'],
);
} // schedule_event_type
if (@$form ['type']['value'] == 'schedule_unavailable_time') {
if ($form ['cid']['value'] === 'new') {
$db = get_global_database_handler();
if (isset($_GET ['faculty_id'])) {
$form ['faculty_id']['value'] = $_GET ['faculty_id'];
}
// Set timezone to the user's timezone (or system if unavail)
$form ['timezone']['value'] = fp_get_user_timezone();
} // new
// Always set the published = TRUE, and hide.
$form ['published']['value'] = TRUE;
$form ['published']['attributes'] = array('class' => 'hidden');
// Always hide faculty_id field.
$form ['faculty_id']['attributes'] = array('class' => 'hidden');
$form ['mark_from'] = array(
'type' => 'markup',
'value' => "<div class='appointment-field-mark calendar-faculty_id'><label>" . t("Faculty/Staff") . ":</label>
" . fp_get_faculty_name($form ['faculty_id']['value']) . "
</div>",
'weight' => $form ['faculty_id']['weight'],
);
} // schedule_unavailable_time
} // content_edit_content_form
}