You are here

public function UserRouteContext::getUserFromRoute in Open Social 8.5

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_user/src/ContextProvider/UserRouteContext.php \Drupal\social_user\ContextProvider\UserRouteContext::getUserFromRoute()
  2. 8 modules/social_features/social_user/src/ContextProvider/UserRouteContext.php \Drupal\social_user\ContextProvider\UserRouteContext::getUserFromRoute()
  3. 8.2 modules/social_features/social_user/src/ContextProvider/UserRouteContext.php \Drupal\social_user\ContextProvider\UserRouteContext::getUserFromRoute()
  4. 8.3 modules/social_features/social_user/src/ContextProvider/UserRouteContext.php \Drupal\social_user\ContextProvider\UserRouteContext::getUserFromRoute()
  5. 8.4 modules/social_features/social_user/src/ContextProvider/UserRouteContext.php \Drupal\social_user\ContextProvider\UserRouteContext::getUserFromRoute()
  6. 8.6 modules/social_features/social_user/src/ContextProvider/UserRouteContext.php \Drupal\social_user\ContextProvider\UserRouteContext::getUserFromRoute()
  7. 8.7 modules/social_features/social_user/src/ContextProvider/UserRouteContext.php \Drupal\social_user\ContextProvider\UserRouteContext::getUserFromRoute()
  8. 8.8 modules/social_features/social_user/src/ContextProvider/UserRouteContext.php \Drupal\social_user\ContextProvider\UserRouteContext::getUserFromRoute()
  9. 10.3.x modules/social_features/social_user/src/ContextProvider/UserRouteContext.php \Drupal\social_user\ContextProvider\UserRouteContext::getUserFromRoute()
  10. 10.0.x modules/social_features/social_user/src/ContextProvider/UserRouteContext.php \Drupal\social_user\ContextProvider\UserRouteContext::getUserFromRoute()
  11. 10.1.x modules/social_features/social_user/src/ContextProvider/UserRouteContext.php \Drupal\social_user\ContextProvider\UserRouteContext::getUserFromRoute()
  12. 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\ContextProvider

Code

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;
      }
    }
  }
}