public function UserCurrentPathsController::wildcardActionRedirect in User current paths (user/edit & user/current/*) 8
Same name and namespace in other branches
- 2.0.x src/Controller/UserCurrentPathsController.php \Drupal\user_current_paths\Controller\UserCurrentPathsController::wildcardActionRedirect()
Handles wildcard (user/current/*) redirects for the current user. Replaces the second "current" parameter in the URL with the currently logged in user and redirects to the target if the resulting path is valid. Ohterwise throws a NotFoundHttpException. This is safe because the redirect is handled as if the user entered the URL manually with all security checks.
Parameters
string $wildcardaction:
Request $request:
Return value
void
1 string reference to 'UserCurrentPathsController::wildcardActionRedirect'
File
- src/
Controller/ UserCurrentPathsController.php, line 24
Class
Namespace
Drupal\user_current_paths\ControllerCode
public function wildcardActionRedirect($wildcardaction = 'view', Request $request) {
$currentUserId = (int) \Drupal::currentUser()
->id();
$path = '/user/' . $currentUserId;
if ($wildcardaction != 'view') {
// /view doesn't exist for user entities
$path .= '/' . $wildcardaction;
}
$url = \Drupal::service('path.validator')
->getUrlIfValid($path);
if ($url !== false) {
// Valid internal path:
return $this
->redirect($url);
}
else {
throw new NotFoundHttpException();
}
}