function splashify_what_paths_check in Splashify 6
Same name and namespace in other branches
- 7 admin/splashify.admin.what.inc \splashify_what_paths_check()
Validate the what:paths field.
We put this in a function so it can handle both the desktop and mobile settings. This assumes that each path in $paths is separated by a new line character. We also assume $paths cannot be blank.
1 call to splashify_what_paths_check()
- splashify_admin_what_form_validate in admin/
splashify.admin.what.inc - Implements form validation handler.
File
- admin/
splashify.admin.what.inc, line 257 - The admin "What" tab.
Code
function splashify_what_paths_check($field, $paths) {
if (empty($paths)) {
form_set_error($field, t('You must enter at least one path.'));
return;
}
// Make sure each path is valid.
$what_paths = preg_split('/[\\n\\r]+/', $paths);
$errors = array();
foreach ($what_paths as $path) {
// If this path is an alias, we know this is a valid path.
if (drupal_lookup_path('source', $path)) {
continue;
}
// If this path is a source url, we know this is a valid path.
if (drupal_lookup_path('alias', $path)) {
continue;
}
// Now check if this is a url value.
$scheme = parse_url($path, PHP_URL_SCHEME);
if ($scheme == 'http' || $scheme == 'https') {
continue;
}
// Finally, check for unaliased internal paths, like "node/4"
if (menu_valid_path(array(
'link_path' => $path,
))) {
continue;
}
// This path is not an alias or the source url.
$errors[] .= t('The path "@path" is not valid.', array(
'@path' => $path,
));
}
// Since there could be multiple errors for this one field, we want to
// break each error into a separate line.
if (count($errors) > 0) {
form_set_error($field, implode('<br />', $errors));
}
}