christmas_lights.module in Christmas Lights 7
Same filename and directory in other branches
Main file for the christmas_lights module.
File
christmas_lights.moduleView source
<?php
/**
* @file
* Main file for the christmas_lights module.
*/
/**
* Implements hook_menu().
*/
function christmas_lights_menu() {
$items['admin/config/system/christmas_lights'] = array(
'title' => 'Chrismas Lights',
'description' => 'A splendid module with Christmas lights decoration that creates longlasting atmosphere of X-mas for you and the users of your website.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'christmas_lights_settings',
),
'access arguments' => array(
'administer site configuration',
),
);
return $items;
}
/**
* Form builder function for module settings.
*/
function christmas_lights_settings() {
$settings = variable_get('christmas_lights_settings');
$start = array(
'day' => date('j', $settings['start']),
'month' => date('n', $settings['start']),
'year' => date('Y', $settings['start']),
);
$end = array(
'day' => date('j', $settings['end']),
'month' => date('n', $settings['end']),
'year' => date('Y', $settings['end']),
);
$form['enabled'] = array(
'#type' => 'checkbox',
'#default_value' => $settings['enabled'],
'#title' => t('Enable christmas lights'),
);
$form['start'] = array(
'#type' => 'date',
'#title' => t('Start date'),
'#default_value' => $start,
'#description' => t('The date your enable christmas lights'),
'#required' => TRUE,
);
$form['end'] = array(
'#type' => 'date',
'#title' => t('Finish date'),
'#default_value' => $end,
'#description' => t('The date your disable christmas lights'),
'#required' => TRUE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save Configuration'),
);
return $form;
}
/**
* Form validation handler for christmas_lights_settings().
*
* @see christmas_lights_settings_submit()
*/
function christmas_lights_settings_validate($form, &$form_state) {
$start = $form_state['values']['start'];
$end = $form_state['values']['end'];
$start = mktime(0, 0, 0, $start['month'], $start['day'], $start['year']);
$end = mktime(0, 0, 0, $end['month'], $end['day'], $end['year']);
if ($start >= $end) {
form_set_error('start', t('You must select a valid start date.'));
}
}
/**
* Process christmas_lights_settings submissions.
*/
function christmas_lights_settings_submit($form, $form_state) {
$settings = variable_get('christmas_lights_settings');
$settings['enabled'] = $form_state['values']['enabled'];
$start = $form_state['values']['start'];
$end = $form_state['values']['end'];
$start = mktime(0, 0, 0, $start['month'], $start['day'], $start['year']);
$end = mktime(0, 0, 0, $end['month'], $end['day'], $end['year']);
$settings['start'] = $start;
$settings['end'] = $end;
variable_set('christmas_lights_settings', $settings);
drupal_set_message(t('Configuration saved.'));
}
/**
* Implements hook_page_build().
*/
function christmas_lights_page_build(&$page) {
$settings = variable_get('christmas_lights_settings');
if ($settings['enabled']) {
if (REQUEST_TIME >= $settings['start'] && REQUEST_TIME <= $settings['end']) {
drupal_add_css(drupal_get_path('module', 'christmas_lights') . '/css/christmas_lights.css');
drupal_add_js(drupal_get_path('module', 'christmas_lights') . '/js/christmas_lights.js', array(
'scope' => 'footer',
));
$page['page_bottom']['christmas_lights']['#markup'] = '<div id="christmas-lights"></div>';
}
}
}
Functions
Name | Description |
---|---|
christmas_lights_menu | Implements hook_menu(). |
christmas_lights_page_build | Implements hook_page_build(). |
christmas_lights_settings | Form builder function for module settings. |
christmas_lights_settings_submit | Process christmas_lights_settings submissions. |
christmas_lights_settings_validate | Form validation handler for christmas_lights_settings(). |