* $form['date'] = array(
* '#type' => 'textfield',
* '#attributes' => array('class' => 'yuicalendar')
* );
*
* // Optionally, set startup parameters.
* $form['#yuicalendar_dateOnly'] = 'false'; // By default
* $form['#yuicalendar_dropDown'] = 'true';
*
*/
/**
* Implementation of hook_form_alter().
*/
function yuicalendar_form_alter($form_id, &$form) {
$editForm = '';
if ($form_id == 'comment_form' && isset($form['admin']) && isset($form['admin']['date'])) {
$editForm = 'admin';
}
elseif (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id && isset($form['author']) && isset($form['author']['date'])) {
$editForm = 'author';
}
if ($editForm != NULL) {
$authorDate = strtotime($form[$editForm]['date']['#default_value']);
$form[$editForm]['#theme'] = 'yui_date_render';
$year = $yearNow = gmdate('Y');
$years = Array();
while ($year >= 1969) {
$years[$year] = $year;
$year--;
}
$form[$editForm]['date']['date-year'] = Array(
'#type' => 'select',
'#attributes' => array('style' => 'display: none;'),
'#default_value' => gmdate('Y', $authorDate),
'#prefix' => '
',
'#suffix' => '
',
'#options' => $years);
$form[$editForm]['date']['date-month'] = Array(
'#type' => 'select',
'#attributes' => array('style' => 'display: none;'),
'#default_value' => (int)gmdate('m', $authorDate),
'#prefix' => '',
'#suffix' => '
',
'#options' => Array(1 => t('JAN'), 2 => t('FEB'), 3 => t('MAR'), 4 => t('APR'), 5 => t('MAY'), 6 => t('JUN'), 7 => t('JUL'), 8 => t('AUG'), 9 => t('SEP'), 10 => t('OCT'), 11 => t('NOV'), 12 => t('DEC')));
$form[$editForm]['date']['date-day'] = Array(
'#type' => 'select',
'#attributes' => array('style' => 'display: none;'),
'#default_value' => (int)(gmdate('d', $authorDate) - 1),
'#prefix' => '',
'#suffix' => '
',
'#options' => Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31));
$form[$editForm]['date']['date-time'] = Array(
'#type' => 'textfield',
'#attributes' => array('style' => 'display: none;'),
'#default_value' => gmdate('H:m:s', $authorDate),
'#size' => 12,
'#maxlength' => 12,
'#prefix' => '');
$form[$editForm]['date']['date-timezone'] = Array(
'#type' => 'hidden',
'#default_value' => gmdate('O', $authorDate));
$form[$editForm]['date']['#attributes'] = array('class' => 'yuicalendar');
$form[$editForm]['date']['#prefix'] = '';
$form[$editForm]['date']['#suffix'] = '
';
}
foreach (element_children($form) as $key) {
if (isset($form[$key]) && isset($form[$key]['#attributes']) && isset($form[$key]['#attributes']['class']) && !(strpos($form[$key]['#attributes']['class'], 'yuicalendar') === FALSE)) {
yuicalendar_load();
$settings = array('dateOnly', 'dropDown');
foreach ($settings as $setting) {
if (isset($form[$key]['#yuicalendar_' . $setting])) {
$form[$key.'_yuicalendar']['#tree'] = TRUE;
$form[$key.'_yuicalendar'][$setting] = array(
'#type' => 'hidden',
'#value' => $form[$key]['#yuicalendar_' . $setting]
);
unset($form[$key]['#yuicalendar_' . $setting]);
}
}
}
// If necessary, recurse through all children.
yuicalendar_form_alter($form_id, $form[$key]);
}
}
function theme_yui_date_render($form) {
$description = $form['date']['#description'];
$title = $form['date']['#title'];
$output = drupal_render_form('name', $form['name']);
//$form['date']['#type'] = 'hidden';
$form['date']['#title'] = $form['date']['#description'] = '';
$tmpOutput = drupal_render_form('date', $form['date']);
$tmpOutput .= drupal_render_form('year', $form['date']['date-year']);
$tmpOutput .= drupal_render_form('month', $form['date']['date-month']);
$tmpOutput .= drupal_render_form('day', $form['date']['date-day']);
$tmpOutput .= drupal_render_form('time', $form['date']['date-time']);
$tmpOutput .= drupal_render_form('time', $form['date']['date-timezone']);
$form['date']['#title'] = $title;
$form['date']['#description'] = $description;
if (isset($form['author'])) {
$output = drupal_render_form('author', $form['author']);
}
$output .= theme_form_element($form['date'], $tmpOutput);
if (isset($form['status'])) {
$output .= drupal_render_form('status', $form['status']);
}
return $output;
}
/**
* Load needed files.
*/
function yuicalendar_load() {
static $loaded = FALSE;
if ($loaded) {
return;
}
$path = drupal_get_path('module', 'yuicalendar');
// get yui package path added by BA
$yui_source='/modules/yui/yui';
if (variable_get('yui_source',0)==0)
{
$yui_source='http://yui.yahooapis.com/2.3.0';
}
// end BA
// YUI
drupal_set_html_head('
');
drupal_add_js($path . '/yuicalendar_init.js');
drupal_add_js($path . '/yuicalendar.js');
drupal_add_css($path . '/yuicalendar.css');
$loaded = TRUE;
}
function yuicalendar_nodeapi(&$node, $op, $teaser, $page) {
switch ($op) {
case 'view':
yuicalendar_load();
}
}