You are here

function path_redirect_edit_form in Path redirect 6

Same name and namespace in other branches
  1. 5 path_redirect.module \path_redirect_edit_form()
1 string reference to 'path_redirect_edit_form'
path_redirect_menu in ./path_redirect.module
Implements hook_menu().

File

./path_redirect.admin.inc, line 319
Administrative page callbacks for the path_redirect module.

Code

function path_redirect_edit_form(&$form_state, $redirect = array()) {

  // Merge default values.
  $redirect += array(
    'rid' => NULL,
    'source' => isset($_GET['source']) ? urldecode($_GET['source']) : '',
    'source_query' => isset($_GET['source_query']) ? path_redirect_get_query_array($_GET['source_query']) : array(),
    'redirect' => isset($_GET['redirect']) ? urldecode($_GET['redirect']) : '',
    'query' => array(),
    'fragment' => '',
    'language' => isset($_GET['language']) ? urldecode($_GET['language']) : '',
    'type' => variable_get('path_redirect_default_status', 301),
  );
  $form['rid'] = array(
    '#type' => 'value',
    '#value' => $redirect['rid'],
  );
  $form['source'] = array(
    '#type' => 'textfield',
    '#title' => t('From'),
    '#description' => t("Enter an internal Drupal path or path alias to redirect (e.g. %example1 or %example2). Fragment anchors (e.g. %anchor) are <strong>not</strong> allowed.", array(
      '%example1' => 'node/123',
      '%example2' => 'taxonomy/term/123',
      '%anchor' => '#anchor',
    )),
    '#size' => 42,
    '#maxlength' => 255,
    '#default_value' => path_redirect_build_url($redirect['source'], $redirect['source_query']),
    '#required' => TRUE,
    '#field_prefix' => $GLOBALS['base_url'] . '/' . (variable_get('clean_url', 0) ? '' : '?q='),
    '#autocomplete_path' => db_table_exists('watchdog') ? 'js/path_redirect/autocomplete_404' : '',
    '#element_validate' => array(
      'path_redirect_validate_source_field',
    ),
  );
  $form['redirect'] = array(
    '#type' => 'textfield',
    '#title' => t('To'),
    '#maxlength' => 560,
    '#default_value' => path_redirect_build_url($redirect['redirect'], $redirect['query'], $redirect['fragment'], TRUE),
    '#required' => TRUE,
    '#description' => t('Enter an internal Drupal path, path alias, or complete external URL (like http://example.com/) to redirect to. Use %front to redirect to the front page.', array(
      '%front' => '<front>',
    )),
    '#element_validate' => array(
      'path_redirect_validate_redirect_field',
    ),
  );

  // This will be a hidden value unless locale module is enabled.
  $form['language'] = array(
    '#type' => 'value',
    '#value' => $redirect['language'],
    '#process' => array(),
  );
  $form['advanced'] = array(
    '#type' => 'fieldset',
    '#title' => t('Advanced options'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['advanced']['type'] = array(
    '#type' => 'select',
    '#title' => t('Redirect status'),
    '#description' => t('You can find more information about HTTP redirect status codes at <a href="@status-codes">@status-codes</a>.', array(
      '@status-codes' => 'http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#3xx_Redirection',
    )),
    '#default_value' => $redirect['type'],
    '#options' => path_redirect_status_code_options(),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  $form['cancel'] = array(
    '#value' => l(t('Cancel'), isset($_REQUEST['destination']) ? $_REQUEST['destination'] : 'admin/build/path-redirect'),
  );
  return $form;
}