UserAspect

final readonly class \TYPO3\CMS\Core\Context\UserAspect

Implements
AspectInterface

The aspect contains information about a user.

Can be used for frontend and backend users.

The aspect is an immutable snapshot: all information is captured when the aspect is created. Code changing the state of a user object needs to set a newly created aspect afterwards to make the change visible.

The aspect can be created from a legacy user authentication object or from a Principal established by the authentication pipeline. For a Principal, "isAdmin" is derived from the role of its context.

Allowed properties:

  • id
  • username
  • isLoggedIn
  • isAdmin
  • groupIds (Array of Ids)
  • groupNames

Table of Contents

Interfaces

AspectInterface
Interface AspectInterface Think of an aspect like a property bag

Methods

__construct()  : mixed
get()  : mixed
Fetch common information about the user
getGroupIds()  : array
Return the groups the user is a member of
getGroupNames()  : array
Get the name of all groups, used in Fluid's IfHasRole ViewHelper
isAdmin()  : bool
Check if admin is set
isLoggedIn()  : bool
A user is logged in if the user has a UID, but does not care about groups.
isUserOrGroupSet()  : bool
Checking if a user is logged in or a group constellation different from "0,-1"

Methods

getGroupIds()

Return the groups the user is a member of

public getGroupIds() : array

For Frontend Users there are two special groups: "-1" = hide at login "-2" = show at any login

Return values

array

getGroupNames()

Get the name of all groups, used in Fluid's IfHasRole ViewHelper

public getGroupNames() : array

Return values

array

isAdmin()

Check if admin is set

public isAdmin() : bool

Return values

bool

isLoggedIn()

A user is logged in if the user has a UID, but does not care about groups.

public isLoggedIn() : bool

For frontend purposes, it is possible to e.g. simulate groups, but this would still be defined as "not logged in".

For backend, only the check on the user ID is used.

Return values

bool

isUserOrGroupSet()

Checking if a user is logged in or a group constellation different from "0,-1"

public isUserOrGroupSet() : bool

Return values

bool —

TRUE if either a login user is found OR if the group list is set to something else than '0,-1' (could be done even without a user being logged in!)

On this page