You are here

function r4032login_form_system_site_information_settings_alter in Redirect 403 to User Login 7

Same name and namespace in other branches
  1. 8 r4032login.module \r4032login_form_system_site_information_settings_alter()
  2. 2.x r4032login.module \r4032login_form_system_site_information_settings_alter()

Implements hook_form_FORM_ID_alter().

File

./r4032login.module, line 34
Redirect denied pages to the user login form.

Code

function r4032login_form_system_site_information_settings_alter(&$form, &$form_state, $form_id) {
  $form['error_page']['r4032login_display_denied_message'] = array(
    '#type' => 'checkbox',
    '#weight' => 5,
    '#title' => t('Display access denied message on login page'),
    '#default_value' => variable_get('r4032login_display_denied_message', TRUE),
  );
  $form['error_page']['r4032login_redirect_to_destination'] = array(
    '#type' => 'checkbox',
    '#weight' => 6,
    '#title' => t('Redirect user to the page they tried to access after login'),
    '#default_value' => variable_get('r4032login_redirect_to_destination', TRUE),
  );
  $form['error_page']['r4032login_access_denied_message'] = array(
    '#type' => 'textarea',
    '#rows' => 1,
    '#weight' => 7,
    '#title' => t("User login 'access denied' message"),
    '#default_value' => variable_get('r4032login_access_denied_message', t('Access denied. You must log in to view this page.')),
    '#states' => array(
      'invisible' => array(
        'input[name="r4032login_display_denied_message"]' => array(
          'checked' => FALSE,
        ),
      ),
    ),
  );
  $form['error_page']['r4032login_access_denied_message_type'] = array(
    '#type' => 'select',
    '#options' => array(
      'error' => t('Error'),
      'warning' => t('Warning'),
      'status' => t('Status'),
    ),
    '#weight' => 8,
    '#title' => t("User login 'access denied' message type"),
    '#default_value' => variable_get('r4032login_access_denied_message_type', 'error'),
    '#states' => array(
      'invisible' => array(
        'input[name="r4032login_display_denied_message"]' => array(
          'checked' => FALSE,
        ),
      ),
    ),
  );
  $form['error_page']['r4032login_redirect_authenticated_users_to'] = array(
    '#type' => 'textfield',
    '#weight' => 9,
    '#title' => t("Redirect authenticated users to"),
    '#description' => t('If an authenticated user tries to access a page they can not, redirect them to the given page. Use <front> for the front page, leave blank for a default access denied page.'),
    '#default_value' => variable_get('r4032login_redirect_authenticated_users_to', ''),
  );
  $form['error_page']['r4032login_user_login_path'] = array(
    '#type' => 'textfield',
    '#weight' => 10,
    '#title' => t("Path to user login form"),
    '#description' => t('The path to the user login form. Omit the beginning slash, ie: user/login'),
    '#default_value' => variable_get('r4032login_user_login_path', 'user/login'),
  );
  $options = array(
    '200' => '200 OK',
    '301' => '301 Moved Permanently',
    '302' => '302 Found',
    '307' => '307 Temporary Redirect',
    '403' => '403 Forbidden',
    '451' => '451 Unavailable For Legal Reasons',
  );
  $form['error_page']['r4032login_default_redirect_code'] = array(
    '#type' => 'select',
    '#weight' => 11,
    '#title' => t("HTTP redirect code"),
    '#description' => t('The redirect code to send. 301 responses may be cached by browsers and proxies, so 302 is normally the correct choice.'),
    '#options' => $options,
    '#default_value' => variable_get('r4032login_default_redirect_code', 302),
  );
  $form['error_page']['matching_paths'] = array(
    '#type' => 'fieldset',
    '#title' => t('Skip redirect for matching pages'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#weight' => 12,
  );
  $form['error_page']['matching_paths']['r4032login_match_noredirect_pages'] = array(
    '#type' => 'textarea',
    '#title' => '<span class="element-invisible">' . t('Only the listed pages') . '</span>',
    '#default_value' => variable_get('r4032login_match_noredirect_pages', ''),
    '#description' => t('Instead of redirecting, the user will get an access deined response and see the standard login form. This may be useful when the response code is important - such as for removing outdated content from search engines.  Use the path node/* for all content.') . ' ' . t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array(
      '%blog' => 'blog',
      '%blog-wildcard' => 'blog/*',
      '%front' => '<front>',
    )),
  );
  return system_settings_form($form);
}