function _node_expire_form_alter_nodeform in Node expire 6.2
Same name and namespace in other branches
- 8 node_expire.nodeapi.inc \_node_expire_form_alter_nodeform()
- 7 node_expire.nodeapi.inc \_node_expire_form_alter_nodeform()
1 call to _node_expire_form_alter_nodeform()
- node_expire_form_alter in ./
node_expire.module - Implementation of hook_form_alter().
File
- ./
node_expire.nodeapi.inc, line 77 - Node API integration.
Code
function _node_expire_form_alter_nodeform(&$ntypes, &$form, &$form_state, $form_id) {
// Check if the Node expire feature is enabled for the node type
$node = isset($form['#node']) ? $form['#node'] : NULL;
// Convert the timestamp into a human readable date
if (is_numeric($node->expire)) {
$node->expire = format_date($node->expire, 'custom', NODE_EXPIRE_FORMAT);
}
// This supports node to never expire.
if (empty($ntypes['default']) && empty($node->expire)) {
$ntypes['required'] = FALSE;
}
if (user_access('edit node expire')) {
$expire_field = array(
'#title' => t('Expiration date'),
'#description' => t('Time date to consider the node expired. Format: %time (YYYY-MM-DD).', array(
'%time' => format_date(time(), 'custom', NODE_EXPIRE_FORMAT),
)),
'#type' => 'textfield',
'#maxlength' => 25,
'#required' => $ntypes['required'],
'#default_value' => $node->expire,
);
// In case jQuery UI module is enabled, use it to
// get the DatePicker widget.
if (module_exists('jquery_ui')) {
jquery_ui_add('ui.datepicker');
drupal_add_js(drupal_get_path('module', 'node_expire') . '/node_expire.js');
drupal_add_css(drupal_get_path('module', 'jquery_ui') . "/jquery.ui/themes/default/ui.datepicker.css");
$min = empty($node->created) ? time() : $node->created;
$min = array(
format_date($min, 'custom', 'Y'),
format_date($min, 'custom', 'm'),
format_date($min, 'custom', 'd'),
);
if (!empty($ntypes['max'])) {
$max = strtotime($ntypes['max'], empty($node->created) ? time() : $node->created);
$max = array(
format_date($max, 'custom', 'Y'),
format_date($max, 'custom', 'm'),
format_date($max, 'custom', 'd'),
);
}
else {
$max = NULL;
}
drupal_add_js(array(
'dateFormat' => NODE_EXPIRE_FORMAT_JS,
'minDate' => $min,
'maxDate' => $max,
), 'setting');
}
}
else {
$expire_field = array(
'#type' => 'value',
'#value' => $node->expire,
);
}
// Put the expire field into 'Publising options' if possible
if (user_access('administer nodes')) {
$form['options']['expire'] =& $expire_field;
}
else {
$form['expire'] =& $expire_field;
}
if (isset($node->expired)) {
$form['node_expire'] = array(
'#type' => 'value',
'#value' => TRUE,
);
}
}