You are here

function publication_date_form_node_form_alter in Publication Date 7

Same name and namespace in other branches
  1. 8.2 publication_date.module \publication_date_form_node_form_alter()
  2. 8 publication_date.module \publication_date_form_node_form_alter()
  3. 7.2 publication_date.module \publication_date_form_node_form_alter()

Implementation of hook_form_BASE_ID_alter().

Display the publication date on the node edit form. @note: This won't work where you have Display Suite/REL enabled.

File

./publication_date.module, line 121
Add a field to nodes containing the publication date.

Code

function publication_date_form_node_form_alter(&$form, &$form_state, $form_id) {
  $node = $form["#node"];
  $form['options']['pubdate'] = array(
    '#type' => 'textfield',
    '#title' => t('Published on'),
    '#maxlength' => 25,
    '#description' => t('Format: %time. Leave blank to use the time of form submission.', array(
      '%time' => format_date(REQUEST_TIME, 'custom', 'Y-m-d H:i:s O'),
    )),
    '#weight' => -1,
  );
  if ($form['nid'] !== NULL && isset($node->published_at) && $node->published_at) {
    $form['options']['pubdate']['#default_value'] = format_date($node->published_at, 'custom', 'Y-m-d H:i:s O');
  }
  $form['#validate'][] = 'publication_date_pubdate_validate';
  $form['#submit'][] = 'publication_date_pubdate_submit';
}