You are here

function path_redirect_edit_form in Path redirect 5

Same name and namespace in other branches
  1. 6 path_redirect.admin.inc \path_redirect_edit_form()
1 call to path_redirect_edit_form()
path_redirect_edit in ./path_redirect.module
Callback for add and edit pages.

File

./path_redirect.module, line 200

Code

function path_redirect_edit_form($edit = array(
  'path' => '',
  'redirect' => '',
  'query' => '',
  'fragment' => '',
  'type' => PATH_REDIRECT_DEFAULT_TYPE,
  'rid' => NULL,
)) {
  $form['path'] = array(
    '#type' => 'textfield',
    '#title' => t('From'),
    '#description' => t('Enter a Drupal path or path alias to redirect. Fragment anchors <em>#foo</em> are <strong>not</strong> allowed.'),
    '#size' => 42,
    '#maxlength' => 255,
    '#default_value' => $edit['path'],
    '#field_prefix' => url(NULL, NULL, NULL, TRUE) . (variable_get('clean_url', 0) ? '' : '?q='),
  );
  $form['redirect'] = array(
    '#type' => 'item',
    '#prefix' => '<div class="container-inline">',
    '#suffix' => '</div>',
    '#title' => t('To'),
    '#description' => '<div style="display:block">' . t('Enter a Drupal path, path alias, or external URL to redirect to. Use %front to redirect to the front page. Enter (optional) queries after "?" and (optional) anchor after "#". Most redirects will not contain queries or fragment anchors.', array(
      '%front' => '<front>',
    )) . '</div>',
  );
  $form['redirect']['redirect'] = array(
    '#type' => 'textfield',
    '#size' => 30,
    '#maxlength' => 255,
    '#default_value' => $edit['redirect'],
  );
  $form['redirect'][] = array(
    '#value' => '?',
  );
  $form['redirect']['query'] = array(
    '#type' => 'textfield',
    '#size' => 12,
    '#maxlength' => 255,
    '#default_value' => $edit['query'],
  );
  $form['redirect'][] = array(
    '#value' => '#',
  );
  $form['redirect']['fragment'] = array(
    '#type' => 'textfield',
    '#size' => 12,
    '#maxlength' => 50,
    '#default_value' => $edit['fragment'],
  );
  $form[] = array(
    '#value' => "<p> </p>",
  );
  $form['type'] = array(
    '#type' => 'fieldset',
    '#title' => t('Redirect Type'),
    '#collapsible' => TRUE,
    '#collapsed' => $edit['type'] == PATH_REDIRECT_DEFAULT_TYPE,
  );
  foreach (path_redirect_status_codes() as $key => $info) {
    $form['type'][]['type'] = array(
      '#type' => 'radio',
      '#title' => $info['title'],
      '#description' => $info['description'],
      '#return_value' => $key,
      '#default_value' => $edit['type'],
    );
  }
  $form['type']['link'] = array(
    '#type' => 'markup',
    '#value' => t('<p>Find more information about http redirect codes <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3">here</a>.</p>'),
  );
  $form['rid'] = array(
    '#type' => 'hidden',
    '#value' => $edit['rid'],
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => $edit['rid'] ? t('Update redirect') : t('Create new redirect'),
  );
  return $form;
}