You are here

function redirect_element_validate_source in Redirect 7.2

Same name and namespace in other branches
  1. 7 redirect.admin.inc \redirect_element_validate_source()

Element validate handler; validate the source of an URL redirect.

See also

redirect_edit_form()

1 string reference to 'redirect_element_validate_source'
redirect_edit_form in ./redirect.admin.inc
Form builder to add or edit an URL redirect.

File

./redirect.admin.inc, line 466
Administrative page callbacks for the redirect module.

Code

function redirect_element_validate_source($element, &$form_state) {
  $value =& $element['#value'];

  // Check that the source contains no URL fragment.
  if (strpos($value, '#') !== FALSE) {
    form_error($element, t('The source path cannot contain an URL fragment anchor.'));
  }
  _redirect_extract_url_options($element, $form_state);

  // Disallow redirections from the frontpage.
  if ($value === '<front>') {
    form_error($element, t('The source path cannot be the front page.'));
  }

  // Cannot create redirects for valid paths.
  if (empty($form_state['values']['override'])) {
    $menu_item = menu_get_item($value);
    if ($menu_item && $menu_item['page_callback'] != 'redirect_redirect' && $value == $menu_item['path']) {
      $form_state['storage']['override_messages']['valid-path'] = t('The source path %path is likely a valid path. It is preferred to <a href="@url-alias">create URL aliases</a> for existing paths rather than redirects.', array(
        '%path' => $value,
        '@url-alias' => url('admin/config/search/path/add'),
      ));
      $form_state['rebuild'] = TRUE;
    }
  }
  return $element;
}