public function UserRouteContext::getUserFromRoute in Open Social 8.6
Same name and namespace in other branches
- 8.9 modules/social_features/social_user/src/ContextProvider/UserRouteContext.php \Drupal\social_user\ContextProvider\UserRouteContext::getUserFromRoute()
- 8 modules/social_features/social_user/src/ContextProvider/UserRouteContext.php \Drupal\social_user\ContextProvider\UserRouteContext::getUserFromRoute()
- 8.2 modules/social_features/social_user/src/ContextProvider/UserRouteContext.php \Drupal\social_user\ContextProvider\UserRouteContext::getUserFromRoute()
- 8.3 modules/social_features/social_user/src/ContextProvider/UserRouteContext.php \Drupal\social_user\ContextProvider\UserRouteContext::getUserFromRoute()
- 8.4 modules/social_features/social_user/src/ContextProvider/UserRouteContext.php \Drupal\social_user\ContextProvider\UserRouteContext::getUserFromRoute()
- 8.5 modules/social_features/social_user/src/ContextProvider/UserRouteContext.php \Drupal\social_user\ContextProvider\UserRouteContext::getUserFromRoute()
- 8.7 modules/social_features/social_user/src/ContextProvider/UserRouteContext.php \Drupal\social_user\ContextProvider\UserRouteContext::getUserFromRoute()
- 8.8 modules/social_features/social_user/src/ContextProvider/UserRouteContext.php \Drupal\social_user\ContextProvider\UserRouteContext::getUserFromRoute()
- 10.3.x modules/social_features/social_user/src/ContextProvider/UserRouteContext.php \Drupal\social_user\ContextProvider\UserRouteContext::getUserFromRoute()
- 10.0.x modules/social_features/social_user/src/ContextProvider/UserRouteContext.php \Drupal\social_user\ContextProvider\UserRouteContext::getUserFromRoute()
- 10.1.x modules/social_features/social_user/src/ContextProvider/UserRouteContext.php \Drupal\social_user\ContextProvider\UserRouteContext::getUserFromRoute()
- 10.2.x modules/social_features/social_user/src/ContextProvider/UserRouteContext.php \Drupal\social_user\ContextProvider\UserRouteContext::getUserFromRoute()
Retrieves the user entity from the current route.
This will try to load the user entity from the route if present.
Return value
\Drupal\user\UserInterface|null A user entity if one could be found, NULL otherwise.
1 call to UserRouteContext::getUserFromRoute()
- UserRouteContext::getRuntimeContexts in modules/
social_features/ social_user/ src/ ContextProvider/ UserRouteContext.php - Gets runtime context values for the given context IDs.
File
- modules/
social_features/ social_user/ src/ ContextProvider/ UserRouteContext.php, line 78
Class
- UserRouteContext
- Class UserRouteContext.
Namespace
Drupal\social_user\ContextProviderCode
public function getUserFromRoute() {
$route_match = $this->currentRouteMatch;
// See if the route has a user parameter and try to retrieve it.
if ($account = $route_match
->getParameter('user')) {
if ($account instanceof UserInterface) {
return $account;
}
elseif (is_numeric($account)) {
$account = $this->userStorage
->load($account);
if ($account instanceof UserInterface) {
return $account;
}
}
}
}