public static function PathChecker::validatePaths in Optimizely 8.0
Same name and namespace in other branches
- 8 src/PathChecker.php \Drupal\optimizely\PathChecker::validatePaths()
validatePaths()
Validate the target paths.
@parm $target_paths An array of the paths to validate. @parm $include Boolean, TRUE if the paths are included or FALSE for exclude paths
Return value
Boolean of TRUE if the paths are valid or a string of the path that failed.
2 calls to PathChecker::validatePaths()
- AddUpdateForm::validateForm in src/
AddUpdateForm.php - Check to make sure the project code is unique except for the default entry which uses the account ID but should support an additional entry to allow for custom settings.
- AjaxEnable::enableDisable in src/
AjaxEnable.php
File
- src/
PathChecker.php, line 31 - Contains \Drupal\optimizely\src\PathChecker
Class
- PathChecker
- Provides static methods to check path validity, etc.
Namespace
Drupal\optimizelyCode
public static function validatePaths($project_paths) {
// Validate entered paths to confirm the paths exist on the website
foreach ($project_paths as $path) {
// Check for sitewide wildcard
if (strpos($path, '*') === 0) {
if (count($project_paths) == 1) {
return TRUE;
}
else {
return $path;
}
}
elseif (strpos($path, '*') !== FALSE) {
$project_wildpath = substr($path, 0, -2);
if (\Drupal::pathValidator()
->isValid($project_wildpath) == FALSE) {
// Look for entries in url_alias
$query = db_query("SELECT * FROM {url_alias} WHERE\n source LIKE :project_wildpath OR alias LIKE :project_wildpath", array(
':project_wildpath' => $project_wildpath . '%',
));
$results = $query
->fetchCol(0);
$project_wildpath_match = count($results);
// No matches found for wildcard path
if (!$project_wildpath_match) {
return $path;
}
}
}
elseif (strpos($path, '?') !== FALSE) {
// Look for entries in menu_router
$project_parmpath = substr($path, 0, strpos($path, '?'));
// Look for entry in url_alias table
if (self::lookupPathAlias($path) === FALSE && self::lookupSystemPath($path) === FALSE && \Drupal::pathValidator()
->isValid($project_parmpath) == FALSE) {
return $path;
}
}
elseif (\Drupal::pathValidator()
->isValid($path) == FALSE) {
// Look for entry in url_alias table
if (self::lookupPathAlias($path) === FALSE && self::lookupSystemPath($path) === FALSE) {
return $path;
}
}
}
return TRUE;
}