event_form_alter
- Versions
- 5
event_form_alter($form_id, &$form)- 6
event_form_alter(&$form, $form_state, $form_id)
Implementation of hook_form_alter
Code
contrib/event/event.module, line 2099
<?php
function event_form_alter(&$form, $form_state, $form_id) {
global $user;
$node = isset($form['#node']) ? $form['#node'] : NULL;
if ($form_id == 'node_type_form') {
// node settings form
$type = (isset($form['old_type']) && isset($form['old_type']['#value'])) ? $form['old_type']['#value'] : NULL;
$form['event'] = array(
'#type' => 'fieldset',
'#title' => t('Event calendar'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['event']['event_nodeapi'] = array(
'#type' => 'radios',
'#title' => t('Show in event calendar'),
'#default_value' => variable_get('event_nodeapi_'. $type, 'never'),
'#options' => array('all' => t('All views'), 'solo' => t('Only in views for this type'), 'never' => t('Never')),
'#description' => t('All views: This content type will be available for display on all calendar views, including with other events.<br />Only in views for this type: This content type will only appear in calendar views specific to this type and never with other events.<br />Never: This content type will not be associated with the events calendar.')
);
}
else if (isset($form['type']) && $form_id == $form['type']['#value'] .'_node_form') {
// node edit form
if (variable_get('event_nodeapi_'. $form['type']['#value'], 'never') != 'never') {
if (isset($form_state['node_preview'])) {
event_pre_render($node);
}
drupal_add_js(drupal_get_path('module', 'event') .'/event_node_edit.js');
$form['event'] = array('#type' => 'fieldset', '#tree' =>TRUE);
$form['event']['has_time'] = array(
'#type' => 'checkbox',
'#title' => t('Event has time'),
'#default_value' => !isset($node->event['has_time']) ? 1 : $node->event['has_time'],
'#weight' => -16,
'#description' => t('Is time important for this event? Uncheck if event takes all day.')
);
$form['event']['has_end_date'] = array(
'#type' => 'checkbox',
'#title' => t('Event has end date'),
'#default_value' => !isset($node->event['has_end_date']) ? 0 : $node->event['has_end_date'],
'#weight' => -14,
'#description' => t('Check if you want to specify an end date for this event, then choose end date below.')
);
// We need to check if the timezone ID was set
if (variable_get('date_default_timezone_id', 0) === 0) {
drupal_set_message(t('Please <a href="!url">select the default timezone</a> for your website before creating events.', array('!url' => url('admin/settings/date-time'))), 'error');
}
$form['event']['start_exploded'] = array(
'#type' => 'event',
'#title' => t('Start date'),
'#default_value' => isset($node->event['start_exploded']) ? $node->event['start_exploded'] : _event_user_time(),
'#weight' => -15,
);
// This needs to be validated only if has_end_date checked
// So we'll do that manually in the form validation function
$form['event']['end_exploded'] = array(
'#type' => 'event',
'#title' => t('End date'),
'#default_value' => isset($node->event['end_exploded']) ? $node->event['end_exploded'] : _event_user_time(),
'#weight' => -13,
'#skip_validate' => TRUE,
);
if (variable_get('event_timezone_input', 'site') == 'input') {
$form['event']['timezone'] = array(
'#type' => 'select',
'#title' => t('Time zone'),
'#default_value' => (isset($node->event['timezone']) ? $node->event['timezone'] : variable_get('date_default_timezone_id', 0)),
'#options' => event_zonelist(),
'#description' => t('Select the time zone this event occurs in.'),
'#weight' => -12
);
}
elseif (variable_get('configurable_timezones', 1) && $user->uid && strlen($user->timezone) && (variable_get('event_timezone_input', 'site') == 'user')) {
$form['event']['timezone'] = array(
'#type' => 'hidden',
'#value' => $user->timezone_id,
);
}
else {
$form['event']['timezone'] = array(
'#type' => 'hidden',
'#value' => variable_get('date_default_timezone_id', 0),
);
}
$form['#validate'][] = 'event_form_validate';
}
}
else if ($form_id == 'system_date_time_settings') {
$zones = event_zonelist('offset');
$form['locale']['date_default_timezone'] = array(
'#type' => 'select',
'#title' => t('Default time zone'),
'#default_value' => variable_get('date_default_timezone_id', 0) .'|'. variable_get('date_default_timezone', 0),
'#options' => $zones,
'#description' => t('Select the default site time zone.')
);
$form['#submit'][] = 'event_extra_setting_form_submit';
}
else if ($form_id == 'user_profile_form') {
if (variable_get('configurable_timezones', 1) && !arg(3)) {
$account = user_load(array('uid' => arg(1)));
$zones = event_zonelist('offset');
$form['timezone']['timezone'] = array(
'#type' => 'select',
'#title' => t('Time zone'),
'#default_value' => strlen($account->timezone) ? ($account->timezone_id .'|'. $account->timezone) : (variable_get('date_default_timezone_id', 0) .'|'. variable_get('date_default_timezone', 0)),
'#options' => $zones,
'#description' => t('Select your current local time. Dates and times throughout this site will be displayed using this time zone.'),
);
$form['#submit'][] = 'event_extra_user_form_submit';
}
}
}
?>


