function path_redirect_validate_source_field in Path redirect 6
Validate a redirect's source path (from) field.
1 string reference to 'path_redirect_validate_source_field'
File
- ./
path_redirect.admin.inc, line 407 - Administrative page callbacks for the path_redirect module.
Code
function path_redirect_validate_source_field($element, &$form_state) {
// Check that the path contains no URL fragment.
if (strpos($element['#value'], '#') !== FALSE) {
form_error($element, t('The source path cannot contain an URL fragment anchor.'));
}
//if (!valid_url($element['#value'])) {
// //Make sure "from" has the form of a local Drupal path
// form_serror($element, t('The source path does not appear valid. This must be a local Drupal path.'));
//}
// @todo Split into source and source_query here.
// A redirect's 'from' cannot match any values from url_alias, it will cause an infinite loop.
if ($pid = db_result(db_query("SELECT pid FROM {url_alias} WHERE dst = '%s'", $element['#value']))) {
form_error($element, t('You cannot add an existing alias as a redirect as it will not work. You must <a href="@alias-delete">delete the alias</a> first.', array(
'@alias-delete' => url('admin/build/path/delete/' . $pid, array(
'query' => drupal_get_destination(),
)),
)));
}
// Cannot create redirects for valid paths.
$menu_item = menu_get_item($element['#value']);
if ($menu_item && $menu_item['page_callback'] != 'path_redirect_goto' && $element['#value'] == $menu_item['path']) {
form_error($element, t('The source path %path is a currently valid path. You cannot override existing paths. You can however, create URL aliases for them.', array(
'%path' => $element['#value'],
)));
}
return $element;
}