function revisioning_scheduler_form_alter in Revisioning 8
Same name and namespace in other branches
- 6.3 revisioning_scheduler/revisioning_scheduler.module \revisioning_scheduler_form_alter()
- 7 revisioning_scheduler/revisioning_scheduler.module \revisioning_scheduler_form_alter()
Implements hook_form_alter().
Adds date and time fields to the publication and reverting forms. Also shows the entered date and time on the revisions summary.
File
- revisioning_scheduler/
revisioning_scheduler.module, line 140 - Allows revisions to be published at specified dates and times.
Code
function revisioning_scheduler_form_alter(&$form, $form_state, $form_id) {
switch ($form_id) {
case 'revisioning_publish_confirm':
case 'node_revision_revert_confirm':
$vid = arg(3);
$result = db_query('SELECT * FROM {revisioning_scheduler} WHERE revision_vid = :vid', array(
':vid' => $vid,
));
$revision = $result
->fetchAssoc();
if (!empty($revision)) {
drupal_set_message(t('This revision was already scheduled by !username for publication on %date. You may override this date and time.', array(
'%date' => format_date($revision['revision_date']),
'!username' => theme('username', array(
'account' => user_load($revision['revision_uid']),
)),
)), 'warning', FALSE);
}
$date_format = variable_get('revisioning_scheduler_date_format');
if (empty($date_format)) {
$date_format = REVISIONING_SCHEDULER_DEFAULT_DATE_FORMAT;
}
$date_and_time = explode(' ', date($date_format));
$form['revisioning_scheduler_date'] = array(
'#title' => $form_id == 'node_revision_revert_confirm' ? t('Date for reversion') : t('Date for publication'),
'#type' => 'textfield',
'#description' => t('Enter the date you want this revision to be published.'),
'#maxlength' => 10,
'#size' => 10,
'#default_value' => $date_and_time[0],
'#weight' => -1,
);
$form['revisioning_scheduler_time'] = array(
'#title' => $form_id == 'node_revision_revert_confirm' ? t('Time for reversion') : t('Time for publication'),
'#type' => 'textfield',
'#maxlength' => 5,
'#size' => 5,
'#default_value' => $date_and_time[1],
'#description' => t('Enter the time you want this revision to be published. Use the 24 hour clock.'),
'#weight' => 0,
);
break;
case 'revisioning_revisions_summary':
$result = db_query('SELECT * FROM {revisioning_scheduler} WHERE revision_nid = :nid', array(
':nid' => arg(1),
));
foreach ($result as $revision) {
if ($revision->revision_date > time()) {
$form['info'][$revision->revision_vid]['#markup'] .= '<br/>' . t('Scheduled for publication on %date.', array(
'%date' => format_date($revision->revision_date, 'long'),
));
}
else {
$form['info'][$revision->revision_vid]['#markup'] .= '<br/>' . t('Scheduled for publication at next cron run.');
}
}
break;
}
}