You are here

comment_delete.admin.inc in Comment Delete 7

Same filename and directory in other branches
  1. 6 comment_delete.admin.inc

File

comment_delete.admin.inc
View source
<?php

/**
 * @file
 * comment_delete.admin.inc
 */

/**
 * Page callback for comment deletion settings form.
 */
function comment_delete_settings_form() {
  $form['comment_delete_default'] = array(
    '#type' => 'radios',
    '#title' => t('Default Delete Option'),
    '#description' => t('Choose the default option selected when a comments deleted.'),
    '#options' => array(
      0 => t('Delete comment and replies'),
      1 => t('Delete comment and move replies up'),
      2 => t('Delete comment and keep replies'),
    ),
    '#required' => TRUE,
    '#default_value' => variable_get('comment_delete_default', 0),
  );
  $form['comment_delete_soft'] = array(
    '#type' => 'checkbox',
    '#title' => t('Soft delete comments'),
    '#description' => t('When enabled the comment subject+body is cleared but comment+author is retained.'),
    '#default_value' => variable_get('comment_delete_soft', 0),
  );
  $form['comment_delete_threshold'] = array(
    '#type' => 'textfield',
    '#title' => t('Threshold Period'),
    '#description' => t('Max allowable time comments can be deleted after creation. Enter zero (0) to disable.'),
    '#size' => 10,
    '#default_value' => variable_get('comment_delete_threshold', 0),
  );
  $form['comment_delete_message'] = array(
    '#type' => 'textarea',
    '#title' => t('Confirmation Message'),
    '#description' => t('Customize confirmation message shown after comment has been deleted.'),
    '#default_value' => variable_get('comment_delete_message', ''),
  );
  return system_settings_form($form);
}

/**
 * Validation callback for comment deletion settings form.
 */
function comment_delete_settings_form_validate($form, &$form_state) {

  // Check threshold is numerical value.
  if (!is_numeric($form_state['values']['comment_delete_threshold'])) {
    form_set_error('comment_delete_threshold', t('Threshold should be greater than or equal to zero (0).'));
  }

  // Check threshold is not negative.
  if ($form_state['values']['comment_delete_threshold'] < 0) {
    form_set_error('comment_delete_threshold', t('Threshold should be greater than or equal to zero (0).'));
  }

  // Check threshold does not include decimals.
  if (preg_match('/\\./i', $form_state['values']['comment_delete_threshold'])) {
    form_set_error('comment_delete_threshold', t('Threshold should not include decimals.'));
  }
}

Functions

Namesort descending Description
comment_delete_settings_form Page callback for comment deletion settings form.
comment_delete_settings_form_validate Validation callback for comment deletion settings form.