You are here

function node_expire_default_settings_form in Node expire 6

Same name and namespace in other branches
  1. 5 node_expire.module \node_expire_default_settings_form()

Configuration form for default expirations for node_expire

1 string reference to 'node_expire_default_settings_form'
node_expire_menu in ./node_expire.module
Implementation of hook_menu().

File

./node_expire.admin.inc, line 136
Module settings.

Code

function node_expire_default_settings_form() {

  // Get current settings
  $curdefaults = variable_get('node-expire-node-visibility', array());
  $period = 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'),
  );

  // Make the options available for each node type.
  $types = node_get_types();
  $form['node-expire-node-visibility'] = array(
    '#tree' => TRUE,
  );
  foreach ($types as $node) {

    // If we don't already have defaults for this node set, use our own.
    if (!$curdefaults[$node->type]) {
      $curdefaults[$node->type] = array(
        'enabled' => FALSE,
        'expiremode' => NODE_EXPIRE_NONE,
        'expire_timefrom' => '+3 months',
        'expire' => '+3 months',
        'isroot' => FALSE,
      );
    }
    $form['node-expire-node-visibility'][$node->type] = array(
      '#type' => 'fieldset',
      '#title' => $node->name,
      '#tree' => TRUE,
      '#collapsible' => TRUE,
      '#collapsed' => $curdefaults[$node->type]['enabled'] == FALSE,
      '#description' => $node->module == 'book' ? t('These defaults will only be used when no inheritance is available.') : '',
    );
    $form['node-expire-node-visibility'][$node->type]['enabled'] = array(
      '#type' => 'checkbox',
      '#title' => t('Enable expiration for this node type.'),
      '#default_value' => $curdefaults[$node->type]['enabled'],
    );
    $form['node-expire-node-visibility'][$node->type]['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' => $curdefaults[$node->type]['expiremode'],
    );
    $form['node-expire-node-visibility'][$node->type]['expire_timefrom'] = array(
      '#title' => t('Expiration Time'),
      '#description' => t('Time after last update to consider the node expired.'),
      '#type' => 'select',
      '#options' => $period,
      '#default_value' => $curdefaults[$node->type]['expire_timefrom'],
    );
    $form['node-expire-node-visibility'][$node->type]['expire'] = array(
      '#title' => t('Expiration Date'),
      '#description' => t('Time/date to consider the node expired. Format: %time or PHP <a href="http://www.php.net/strtotime" target="_blank">strtotime format</a>. Note that if the default date entered is in the past at the node post time, and the end-user doesn\'t have access to edit it, the expiration settings for that node will be removed.', array(
        '%time' => format_date(time(), 'large'),
      )),
      '#type' => 'textfield',
      '#default_value' => $curdefaults[$node->type]['expire'],
      '#attributes' => array(
        'class' => 'jscalendar',
      ),
    );

    // As book pages is the only node type that allows inheritance, only show it there.
    if ($node->module == 'book' and variable_get('node-expire-book-props', 1) == 1) {
      $form['node-expire-node-visibility'][$node->type]['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' => $curdefaults[$node->type]['isroot'],
      );
    }
  }

  // Use the Drupal's standard
  $form = system_settings_form($form);
  $form['#validate'][] = 'node_expire_default_settings_form_validate';
  $form['#submit'][] = 'node_expire_default_settings_form_submit';
  return $form;
}