function scheduler_form_alter in Scheduler 5
Same name and namespace in other branches
- 6 scheduler.module \scheduler_form_alter()
- 7 scheduler.module \scheduler_form_alter()
- 2.x scheduler.module \scheduler_form_alter()
Implementation of hook_form_alter().
File
- ./
scheduler.module, line 75
Code
function scheduler_form_alter($form_id, &$form) {
//allow scheduling on a per-node-type basis
if ('node_type_form' == $form_id) {
$form['workflow']['scheduler'] = array(
'#type' => 'checkbox',
'#title' => t('Enable scheduled (un)publishing'),
'#default_value' => variable_get('scheduler_' . $form['#node_type']->type, 0),
'#description' => t('Check this box to enable scheduled (un)publishing for this node type.'),
);
$form['workflow']['scheduler_touch'] = array(
'#type' => 'checkbox',
'#title' => t('Alter published on time'),
'#default_value' => variable_get('scheduler_touch_' . $form['#node_type']->type, 0),
'#description' => t('Check this box to alter the published on time to match the scheduled time ("touch feature").'),
);
}
else {
if (isset($form['type']['#value']) && $form['type']['#value'] . '_node_form' == $form_id) {
if (user_access('schedule (un)publishing of nodes')) {
// if scheduling has been enabled for this node type
if (variable_get('scheduler_' . $form['type']['#value'], 0) == 1) {
// We add the additional validation function this way to preserve any existing validation function
$form['#validate']['_scheduler_form_validate'] = array();
//use JScalendar picker for dates if the module exists and is enabled
$jscalendar = FALSE;
if (module_exists('jscalendar')) {
$jscalendar = TRUE;
}
$node = $form['#node'];
//only load the values if we are viewing an existing node
if ($node->nid > 0) {
$defaults = db_fetch_object(db_query('SELECT publish_on, unpublish_on FROM {scheduler} WHERE nid = %d', $node->nid));
}
else {
// init standard values
$defaults = new StdClass();
$defaults->publish_on = $defaults->unpublish_on = NULL;
}
$form['scheduler_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Scheduling options'),
'#collapsible' => TRUE,
'#collapsed' => $defaults->publish_on != 0 || $defaults->unpublish_on != 0 ? FALSE : TRUE,
'#weight' => 35,
);
$date_format = variable_get('scheduler_date_format', SCHEDULER_DATE_FORMAT);
$form['scheduler_settings']['publish_on'] = array(
'#type' => 'textfield',
'#title' => t('Publish on'),
'#maxlength' => 25,
'#default_value' => $defaults->publish_on ? format_date($defaults->publish_on, 'custom', $date_format) : '',
'#description' => t('Format: %time. Leave blank to disable scheduled publishing.', array(
'%time' => format_date(time(), 'custom', $date_format),
)),
'#attributes' => $jscalendar ? array(
'class' => 'jscalendar',
) : array(),
'#jscalendar_timeFormat' => _scheduler_get_jscalendar_time_format(),
'#jscalendar_ifFormat' => _scheduler_date_format_in_strftime_syntax(),
);
$form['scheduler_settings']['unpublish_on'] = array(
'#type' => 'textfield',
'#title' => t('Unpublish on'),
'#maxlength' => 25,
'#default_value' => $defaults->unpublish_on ? format_date($defaults->unpublish_on, 'custom', $date_format) : '',
'#description' => t('Format: %time. Leave blank to disable scheduled unpublishing.', array(
'%time' => format_date(time(), 'custom', $date_format),
)),
'#attributes' => $jscalendar ? array(
'class' => 'jscalendar',
) : array(),
'#jscalendar_timeFormat' => _scheduler_get_jscalendar_time_format(),
'#jscalendar_ifFormat' => _scheduler_date_format_in_strftime_syntax(),
);
}
}
}
}
}