You are here

recently_read.admin.inc in Recently Read 7.2

Functionality for Recently read administration.

File

recently_read.admin.inc
View source
<?php

/**
 * @file
 * Functionality for Recently read administration.
 */

/**
 * Menu callback: Recently read admin settings form page.
 * Form builder; Configure recently read settings.
 */
function recently_read_settings($form, &$form_state) {
  $types = node_type_get_types();
  $options = array();
  foreach ($types as $key => $type) {
    $options[$key] = $type->name;
  }
  $form['node_types'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Enable history tracking of the following content'),
    '#description' => t('Select which content types will be tracked.'),
    '#default_value' => variable_get('recently_read_node_types', array(
      'page',
      'article',
    )),
    '#options' => $options,
  );
  $form['anonymous_enabled'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable history tracking also for anonymous users'),
    '#description' => t('If disabled, login is required to view recently read block.'),
    '#default_value' => variable_get('recently_read_anonymous_enabled', FALSE),
  );
  $form['max_entries'] = array(
    '#type' => 'textfield',
    '#title' => t('Recently read list length'),
    '#description' => 'Provide the maximum number of entires stored for each read content type (per user) in the database.',
    '#default_value' => variable_get('recently_read_max_entries', 10),
    '#required' => TRUE,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save configuration'),
  );
  return $form;
}

/**
 * Implements FORM_ID_validate().
 */
function recently_read_settings_validate($form, &$form_state) {
  $max = $form_state['values']['max_entries'];
  if (!is_numeric($max) || $max < 1) {
    form_set_error('max_entries', t('%field must be a positive integer value.', array(
      '%field' => $form['max_entries']['#title'],
    )));
  }
}

/**
 * Implements FORM_ID_submit().
 */
function recently_read_settings_submit($form, &$form_state) {
  $selected = array();
  foreach ($form_state['values']['node_types'] as $value) {
    if ($value) {
      $selected[] = $value;
    }
  }
  variable_set('recently_read_node_types', $selected);
  variable_set('recently_read_max_entries', $form_state['values']['max_entries']);
  variable_set('recently_read_anonymous_enabled', $form_state['values']['anonymous_enabled']);
  drupal_set_message(t('The configuration options have been saved.'));
}

Functions

Namesort descending Description
recently_read_settings Menu callback: Recently read admin settings form page. Form builder; Configure recently read settings.
recently_read_settings_submit Implements FORM_ID_submit().
recently_read_settings_validate Implements FORM_ID_validate().