You are here

function node_expire_form_alter in Node expire 6

Same name and namespace in other branches
  1. 8 node_expire.module \node_expire_form_alter()
  2. 5 node_expire.module \node_expire_form_alter()
  3. 6.2 node_expire.module \node_expire_form_alter()
  4. 7.2 node_expire.module \node_expire_form_alter()
  5. 7 node_expire.module \node_expire_form_alter()

Implementation of hook_form_alter().

Add expiration options to the node entry forms

File

./node_expire.module, line 27

Code

function node_expire_form_alter(&$form, &$form_state, $form_id) {
  if (isset($form['type']) and $form['type']['#value'] . '_node_form' == $form_id) {

    // Check if the Node Expire feature is enabled for the node type
    $node = isset($form['#node']) ? $form['#node'] : NULL;
    $curdefaults = variable_get('node-expire-node-visibility', array());
    if (empty($curdefaults[$node->type])) {
      return;
    }
    if (user_access('edit expirations') and $node->type != 'book') {
      $form['expiration'] = array(
        '#title' => t('Expiration'),
        '#type' => 'fieldset',
        '#tree' => FALSE,
        '#collapsible' => TRUE,
        '#collapsed' => $node->expiremode == NODE_EXPIRE_NONE,
      );
      $form['expiration']['expiremode'] = array(
        '#title' => t('Expiration Type'),
        '#description' => t('What type of node expiration should this node have?'),
        '#type' => 'select',
        '#options' => array(
          NODE_EXPIRE_NONE => t("Doesn't Expire"),
          NODE_EXPIRE_DATE => t('Expire on Date'),
          NODE_EXPIRE_ONUPDATE => t('Expire After Last Update'),
        ),
        '#default_value' => $node->expiremode,
      );
      $form['expiration']['expire_timefrom'] = array(
        '#title' => t('Expiration Time'),
        '#description' => t('Time after last update to consider the node expired.'),
        '#type' => 'select',
        '#options' => array(
          '+1 day' => t('1 Day'),
          '+2 days' => t('!number Days', array(
            '!number' => 2,
          )),
          '+3 days' => t('!number Days', array(
            '!number' => 3,
          )),
          '+4 days' => t('!number Days', array(
            '!number' => 4,
          )),
          '+5 days' => t('!number Days', array(
            '!number' => 5,
          )),
          '+6 days' => t('!number Days', array(
            '!number' => 6,
          )),
          '+1 week' => t('1 Week'),
          '+2 weeks' => t('!number Weeks', array(
            '!number' => 2,
          )),
          '+3 weeks' => t('!number Weeks', array(
            '!number' => 3,
          )),
          '+1 month' => t('1 Month'),
          '+2 months' => t('!number Months', array(
            '!number' => 2,
          )),
          '+3 months' => t('!number Months', array(
            '!number' => 3,
          )),
          '+4 months' => t('!number Months', array(
            '!number' => 4,
          )),
          '+5 months' => t('!number Months', array(
            '!number' => 5,
          )),
          '+6 months' => t('!number Months', array(
            '!number' => 6,
          )),
          '+7 months' => t('!number Months', array(
            '!number' => 7,
          )),
          '+8 months' => t('!number Months', array(
            '!number' => 8,
          )),
          '+9 months' => t('!number Months', array(
            '!number' => 9,
          )),
          '+10 months' => t('!number Months', array(
            '!number' => 10,
          )),
          '+11 months' => t('!number Months', array(
            '!number' => 11,
          )),
          '+1 Year' => t('1 Year'),
        ),
        '#default_value' => $node->expire_timefrom,
      );
      if (!is_numeric($node->expire)) {
        $node->expire = strtotime($node->expire);
      }
      $form['expiration']['expire'] = array(
        '#title' => t('Expiration Date'),
        '#description' => t('Time date to consider the node expired. Format: %time.', array(
          '%time' => format_date($node->expire, 'custom', NODE_EXPIRE_FORMAT),
        )),
        '#type' => 'textfield',
        '#maxlength' => 25,
        '#default_value' => format_date($node->expire, 'custom', NODE_EXPIRE_FORMAT),
        '#attributes' => array(
          'class' => 'jscalendar',
        ),
      );

      // As book pages is the only node type that allows inheritance, only show it there.
      if ($form['type']['#value'] == 'book' and variable_get('node-expire-book-props', 1) == 1) {
        $form['expiration']['isroot'] = array(
          '#title' => t('Block Inheritance'),
          '#description' => t('Whether or not to block inheritance of the above settings from parent nodes.'),
          '#type' => 'checkbox',
          '#default_value' => $node->isroot,
        );
      }
    }
    else {
      $form['expiration']['expiremode'] = array(
        '#type' => 'value',
        '#value' => $node->expiremode,
      );
      $form['expiration']['expire_timefrom'] = array(
        '#type' => 'value',
        '#value' => $node->expire_timefrom,
      );
      $form['expiration']['expire'] = array(
        '#type' => 'value',
        '#value' => $node->expire,
      );
      if ($form['type']['#value'] == 'book' and variable_get('node-expire-book-props', 1) == 1) {
        $form['expiration']['isroot'] = array(
          '#type' => 'value',
          '#value' => $node->isroot,
        );
      }
    }
    $form['expiration']['node_expire'] = array(
      '#type' => 'value',
      '#value' => $node->node_expire,
    );
  }
}