You are here

function login_destination_edit_form in Login Destination 7

Category edit page.

1 string reference to 'login_destination_edit_form'
login_destination_menu in ./login_destination.module
Implements hook_menu().

File

./login_destination.admin.inc, line 346
Admin page callback file for the Login Destination module.

Code

function login_destination_edit_form($form, &$form_state, array $rule = array()) {

  // Default values.
  $rule += array(
    'triggers' => array(),
    'roles' => array(),
    'pages_type' => LOGIN_DESTINATION_REDIRECT_NOTLISTED,
    'pages' => '',
    'destination_type' => LOGIN_DESTINATION_STATIC,
    'destination' => '<front>',
    'id' => NULL,
    'weight' => 0,
  );
  $access = user_access('use PHP for settings');
  $type = $rule['destination_type'];
  if ($type == LOGIN_DESTINATION_SNIPPET && !$access) {
    $form['destination_type'] = array(
      '#type' => 'value',
      '#value' => LOGIN_DESTINATION_SNIPPET,
    );
    $form['destination'] = array(
      '#type' => 'value',
      '#value' => $rule['destination'],
    );
  }
  else {
    $options = array(
      LOGIN_DESTINATION_STATIC => t('Internal page or external URL'),
    );
    $description = t("Specify page by using its path. Example path is %blog for the blog page. %front is the front page. %current is the current page. Precede with http:// for an external URL. Leave empty to redirect to a default page.", array(
      '%blog' => 'blog',
      '%front' => '<front>',
      '%current' => '<current>',
    ));
    if ($access && module_exists('php')) {
      $options += array(
        LOGIN_DESTINATION_SNIPPET => t('Page returned by this PHP code (experts only)'),
      );
      $description .= ' ' . t('If the PHP option is chosen, enter PHP code between %php. It should return either a string value or an array of params that the %function function will understand, for example. %example. For more information, see the online API entry for <a href="@url">url function</a>. Note that executing incorrect PHP code can break your Drupal site.', array(
        '%php' => '<?php ?>',
        '%function' => 'url($path = \'\', array $options = array())',
        '%example' => '<?php return array(\'blog\', array(\'fragment\' => \'overlay=admin/config\', ), ); ?>',
        '@url' => 'http://api.drupal.org/api/drupal/includes--common.inc/function/url/7',
      ));
    }
    $form['destination_type'] = array(
      '#type' => 'radios',
      '#title' => t('Redirect to page'),
      '#default_value' => $type,
      '#options' => $options,
    );
    $form['destination'] = array(
      '#type' => 'textarea',
      '#default_value' => $rule['destination'],
      '#description' => $description,
    );

    // Add token help if module is enabled.
    if (module_exists('token')) {
      $form['token_help'] = array(
        '#theme' => 'token_tree',
        '#token_types' => array(),
        '#dialog' => TRUE,
      );
    }
  }
  $triggers = array_map('check_plain', $rule['triggers']);
  if (empty($triggers)) {
    $triggers = array();
  }
  $form['triggers'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Redirect upon triggers'),
    '#options' => array(
      'login' => t('Login, registration, one-time login link'),
      'logout' => t('Logout'),
    ),
    '#default_value' => $triggers,
    '#description' => t('Redirect only upon selected trigger(s). If you select no triggers, all of them will be used.'),
  );
  $type = $rule['pages_type'];
  if ($type == LOGIN_DESTINATION_REDIRECT_PHP && !$access) {
    $form['pages_type'] = array(
      '#type' => 'value',
      '#value' => LOGIN_DESTINATION_REDIRECT_PHP,
    );
    $form['pages'] = array(
      '#type' => 'value',
      '#value' => $rule['destination'],
    );
  }
  else {
    $options = array(
      LOGIN_DESTINATION_REDIRECT_NOTLISTED => t('All pages except those listed'),
      LOGIN_DESTINATION_REDIRECT_LISTED => t('Only the listed pages'),
    );
    $description = 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. %login is the login form. %register is the registration form. %reset is the one-time login (e-mail validation).", array(
      '%blog' => 'blog',
      '%blog-wildcard' => 'blog/*',
      '%front' => '<front>',
      '%login' => 'user',
      '%register' => 'user/register',
      '%reset' => 'user/*/edit',
    ));
    if ($access && module_exists('php')) {
      $options += array(
        LOGIN_DESTINATION_REDIRECT_PHP => t('Pages on which this PHP code returns <code>TRUE</code> (experts only)'),
      );
      $description .= ' ' . t('If the PHP option is chosen, enter PHP code between %php. Note that executing incorrect PHP code can break your Drupal site.', array(
        '%php' => '<?php ?>',
      ));
    }
    $form['pages_type'] = array(
      '#type' => 'radios',
      '#title' => t('Redirect from specific pages'),
      '#default_value' => $type,
      '#options' => $options,
    );
    $form['pages'] = array(
      '#type' => 'textarea',
      '#default_value' => $rule['pages'],
      '#description' => $description,
    );
  }
  $default_role_options = array_map('check_plain', $rule['roles']);
  if (empty($default_role_options)) {
    $default_role_options = array();
  }
  $form['roles'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Redirect users with roles'),
    '#options' => _login_destination_role_options(),
    '#default_value' => $default_role_options,
    '#description' => t('Redirect only the selected role(s). If you select no roles, all users will be redirected.'),
  );
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  if ($rule['id']) {
    $form['id'] = array(
      '#type' => 'hidden',
      '#value' => $rule['id'],
    );
  }
  return $form;
}