function _node_expire_form_alter_nodeform in Node expire 8
Same name and namespace in other branches
- 6.2 node_expire.nodeapi.inc \_node_expire_form_alter_nodeform()
- 7 node_expire.nodeapi.inc \_node_expire_form_alter_nodeform()
Implements hook_form_alter().
Adds expiration options to the node entry forms
1 call to _node_expire_form_alter_nodeform()
- node_expire_form_alter in ./
node_expire.module - Implements hook_form_alter().
File
- ./
node_expire.nodeapi.inc, line 233 - Node API integration.
Code
function _node_expire_form_alter_nodeform(&$ntype, &$form, &$form_state, $form_id) {
// Check if the Node expire feature is enabled for the node type.
$node = isset($form['#node']) ? $form['#node'] : NULL;
$handle_content_expiry = \Drupal::config('node_expire.settings')
->get('node_expire_handle_content_expiry');
if ($handle_content_expiry != 0) {
if (empty($ntype['enabled'])) {
return;
}
// Replace not set to default string.
if (!isset($node->expire)) {
// $ntype = isset($ntypes[$node->type]) ? $ntypes[$node->type] : NULL;
$node->expire = _node_expire_date_db_to_str('', $ntype);
}
}
else {
// Replace not set to empty string.
if (!isset($node->expire)) {
$node->expire = '';
}
// Convert the timestamp into a human readable date - legacy branch.
if (is_numeric($node->expire)) {
$node->expire = format_date($node->expire, 'custom', NODE_EXPIRE_FORMAT);
}
}
// This supports node to never expire.
if (empty($ntype['default']) && empty($node->expire)) {
$ntype['required'] = FALSE;
}
if (\Drupal::currentUser()
->hasPermission('edit node expire')) {
if (_node_expire_get_date_entry_elements()) {
// Date popups.
$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(REQUEST_TIME, 'custom', NODE_EXPIRE_FORMAT),
)),
'#type' => 'date_popup',
'#date_format' => NODE_EXPIRE_FORMAT,
'#required' => $ntype['required'],
'#default_value' => $node->expire,
);
}
else {
// Text fields.
$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(REQUEST_TIME, 'custom', NODE_EXPIRE_FORMAT),
)),
'#type' => 'textfield',
'#maxlength' => 25,
'#required' => $ntype['required'],
'#default_value' => $node->expire,
);
}
}
else {
$expire_field = array(
'#type' => 'value',
'#value' => $node->expire,
);
}
// If the form doesn't have the publishing options we'll create our own.
if (!$form['options']['#access']) {
$form['options1'] = array(
'#type' => 'fieldset',
'#title' => t('Publishing options'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#weight' => 95,
);
$form['options1']['expire'] =& $expire_field;
}
else {
$form['options']['expire'] =& $expire_field;
}
if (isset($node->expired)) {
$form['node_expire'] = array(
'#type' => 'value',
'#value' => TRUE,
);
}
}