You are here

function login_destination_admin_settings in Login Destination 6.2

Same name and namespace in other branches
  1. 5 login_destination.module \login_destination_admin_settings()
  2. 6 login_destination.module \login_destination_admin_settings()
1 string reference to 'login_destination_admin_settings'
login_destination_menu in ./login_destination.module
Implementation of hook_menu().

File

./login_destination.module, line 44
Control where users are directed to, once they login

Code

function login_destination_admin_settings() {
  $form = array();

  // to where we redirect
  $form['destination'] = array(
    '#type' => 'fieldset',
    '#title' => t('Destination URL settings'),
    '#description' => t('To where exactly should the user be redirected upon login.'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['destination']['ld_destination'] = array(
    '#type' => 'checkbox',
    '#default_value' => variable_get('ld_destination', TRUE),
    '#title' => t('Return user to where he/she came from. (Preserve destination)'),
    '#description' => t("If checked, 'destination=' parameter specified in the URL will be used to perform redirection.<br />\n      <b>NOTE</b>: All options below will be ignored then!."),
  );
  $form['destination']['ld_url_type'] = array(
    '#type' => 'radios',
    '#default_value' => variable_get('ld_url_type', LOGIN_DEST_STATIC),
    '#options' => array(
      LOGIN_DEST_STATIC => t('Static URL'),
      LOGIN_DEST_SNIPPET => t('PHP snippet (experts only)'),
    ),
  );
  $form['destination']['ld_url_destination'] = array(
    '#type' => 'textarea',
    '#default_value' => variable_get('ld_url_destination', 'user'),
    '#title' => t('URL: (<b>IMPORTANT! If using a WYSWYG editor - ensure that you use its plain text mode!
      There is a link below the text box.</b> )'),
    '#rows' => 4,
    '#description' => t('<b>Static URL mode:</b> Enter a static path. Do not use a GET query at the end here. Only the first line of text will be used.
      Example paths are %ex1 or %ex2.', array(
      '%ex1' => 'node/add',
      '%ex2' => 'contact',
    )) . '<br/>' . '<b>' . t("PHP snippet mode") . ": </b>" . t("Enter PHP code to evaluate path") . "(<b>" . t("NO %php tags!", array(
      '%php' => '<?php ?>',
    )) . "</b>)." . t("It should return either a string value or an array like in:<br>\n        <blockquote><tt>@array</tt></blockquote>", array(
      '@array' => "return array('path' => 'node/add/page', 'query' => array('param1' => '100', 'param2' => '200'));",
    )),
  );

  // turn on/off the drupal_goto invocation
  // off by default
  // we need ld_use_drupal_goto == ON, if we want to use absolute urls on login redirect, at least until some better way is found
  $form['use_drupal_goto'] = array(
    '#type' => 'fieldset',
    '#title' => t('Use drupal_goto when redirecting ?'),
    '#description' => t('We need the drupal_goto() function, if we want to use absolute urls (e.g. http://example.com) on login redirect.<br>
( That is at least until some better way is found, because using drupal_goto will break modules like content_profile_registration from the content_profile package. )'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['use_drupal_goto']['ld_use_drupal_goto'] = array(
    '#type' => 'radios',
    '#default_value' => variable_get('ld_use_drupal_goto', 0),
    '#options' => array(
      0 => t('Don\'t use drupal_goto(). (DEFAULT OPTION) ( Redirecting to absolute urls won\'t work, but they are rarely needed for redirect destinations.
On the other hand, content_profile_registration will work with this option selected. )'),
      1 => t('Use drupal_goto(). ( NOTE: will break content_profile_registration saving user data on register. Redirecting to absolute urls will work. )'),
    ),
    '#description' => t('MORE INFO: If your site has set these two settings at admin/user/settings:<br>
1. Selected: "Visitors can create accounts and no administrator approval is required."<br>
2. Unchecked: "Require e-mail verification when a visitor creates an account"<br>
<br>
The "Use drupal_goto()" above will prevent the content_profile_registration custom user fields from being saved and will redirect directly to
 the absolute/relative url you\'ve setup here.<br>'),
  );

  // on which pages we redirect
  $form['condition'] = array(
    '#type' => 'fieldset',
    '#title' => t('Redirection conditions'),
    '#description' => t('When should redirection happen?'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['condition']['ld_condition_type'] = array(
    '#type' => 'radios',
    '#default_value' => variable_get('ld_condition_type', 'always'),
    '#options' => array(
      LOGIN_COND_ALWAYS => t('Always'),
      LOGIN_COND_PAGES => t('List of paths'),
      LOGIN_COND_SNIPPET => t('PHP snippet (experts only)'),
    ),
  );
  $form['condition']['ld_condition_snippet'] = array(
    '#type' => 'textarea',
    '#default_value' => variable_get('ld_condition_snippet', ''),
    '#title' => t('Redirect condition: <b>IMPORTANT! If using a WYSIWYG editor - ensure that you use its plain text mode! There is a link below the text box.</b>'),
    '#rows' => 4,
    '#description' => t('<b>Always:</b> Redirection happens always. Redirect condition field is ignored.') . '<br/>' . t('<b>List of paths mode:</b> Enter a list of paths, one path per one line. Redirection will happen only when logging from specified pages. Example paths are <b>%ex1</b> or <b>%ex2</b>.', array(
      '%ex1' => 'contact',
      '%ex2' => 'user/login',
    )) . '<br/>' . t('<b>PHP snippet mode:</b> Enter PHP code to find should redirection happen or not (<b>NO %php tags!</b>). It should return a boolean value.', array(
      '%php' => '<?php ?>',
    )),
  );
  return system_settings_form($form);
}