1 path.inc | backdrop_valid_path($path, $dynamic_allowed = FALSE) |
Checks a path exists and the current user has access to it.
Parameters
$path: The path to check.
$dynamic_allowed: Whether paths with menu wildcards (like user/%) should be allowed.
Return value
TRUE if it is a valid path AND the current user has access permission,: FALSE otherwise.
File
- core/
includes/ path.inc, line 551 - Functions to handle paths in Backdrop, including URL aliasing.
Code
function backdrop_valid_path($path, $dynamic_allowed = FALSE) {
global $menu_admin;
// We indicate that a menu administrator is running the menu access check.
$menu_admin = TRUE;
if ($path == '<front>' || url_is_external($path)) {
$item = array('access' => TRUE);
}
elseif ($dynamic_allowed && preg_match('/\/\%/', $path)) {
// Path is dynamic (ie 'user/%'), so check directly against menu_router table.
if ($item = db_query("SELECT * FROM {menu_router} where path = :path", array(':path' => $path))->fetchAssoc()) {
$item['link_path'] = $item['path'];
$item['link_title'] = $item['title'];
$item['external'] = FALSE;
$item['options'] = '';
_menu_link_translate($item);
}
}
else {
$item = menu_get_item($path);
}
$menu_admin = FALSE;
return $item && $item['access'];
}