typo3-rector
typo3-rector copied to clipboard
Breaking: #102605 - TSFE->fe_user removed
Breaking: #102605 - TSFE->fe_user removed
https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/13.0/Breaking-102605-TSFE-fe_userRemoved.html
Breaking: #102605 - TSFE->fe_user removed
See 102605
Description
Frontend related property TypoScriptFrontendController->fe_user
has
been removed.
When looking at the TYPO3 Frontend rendering chain, class
TypoScriptFrontendController
is by far the biggest technical debt: It
mixes a lot of concerns and carries tons of state and functionality that
should be modeled differently, which leads to easier to understand and
more flexible code. The class is shrinking since various major versions
already and will ultimately dissolve entirely at some point. Changes in
this area are becoming more aggressive with TYPO3 v13. Any code using
the class will need adaptions at some point, single patches will
continue to communicate alternatives.
In case of the fe_user
property, two alternatives exist: The frontend
user can be retrieved from the Request
attribute frontend.user
, and
basic frontend user information is available using the Context
aspect
frontend.user
.
Note accessing TypoScript TSFE:fe_user
details continues to work for
now, using for example lib.foo.data = TSFE:fe_user|user|username
to
retrieve the username of a logged in user is still ok.
Impact
Using TypoScriptFrontendController->fe_user
(or
$GLOBALS['TSFE']->fe_user
) will raise a PHP fatal error.
Affected installations
Instances with extensions dealing with frontend user details may be affected, typically custom login extensions or extensions consuming detail data of logged in users.
Migration
There are two possible migrations.
First, a limited information list of frontend user details can be
retrieved using the Context
aspect frontend.user
in Frontend calls.
See class TYPO3\CMS\Core\Context\UserAspect
for a full list. The
current context can retrieved using dependency injection. Example:
use TYPO3\CMS\Core\Context\Context;
final class MyExtensionController {
public function __construct(
private readonly Context $context,
) {}
public function myAction() {
$frontendUserUsername = $this->context->getPropertyFromAspect('frontend.user', 'username', ''));
}
}
Additionally, the full
TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication
object is
available as request attribute frontend.user
in the frontend. Note
some details of that object are marked @internal
, using the context
aspect is thus the preferred way. Example of an extension using the
extbase ActionController
:
final class MyExtensionController extends ActionController {
public function myAction() {
// Note the 'user' property is marked @internal.
$frontendUserUsername = $this->request->getAttribute('frontend.user')->user['username'];
}
}
Frontend, PHP-API, FullyScanned, ext:frontend
$this->request->getAttribute('frontend.user')->user['tx_custom_field']
@simonschaufi Useful to add constructor dependencies is the class Rector\NodeManipulator\ClassDependencyManipulator
Code examples:
EXT:powermail:
-
$typoScriptFrontend->fe_user->setKey('ses', 'powermail', 'value');
-
$typoScriptFrontend->fe_user->getKey('ses', 'powermail');
-
$typoScriptFrontend->fe_user->user['uid']
-
$typoScriptFrontend->fe_user->user['usergroup']
-
$GLOBALS['TSFE']->fe_user = new FrontendUserAuthentication();
-
$typoScriptFrontend->fe_user->setAndSaveSessionData('tx_powermail_cond', $array);
$tsfe = ObjectUtility::getTyposcriptFrontendController();
if (!empty($tsfe->fe_user->user[$propertyName])) {
return (string)$tsfe->fe_user->user[$propertyName];
}
EXT:solr:
-
'cookie' => $TSFE->fe_user->id ?? '',
-
$GLOBALS['TSFE']->fe_user->user['username'] = AuthorizationService::SOLR_INDEXER_USERNAME;
-
$GLOBALS['TSFE']->fe_user->user['usergroup'] = $groupList;
-
$frontendUserAuthentication = $GLOBALS['TSFE']->fe_user;
if (!is_array($GLOBALS['TSFE']->fe_user->user)) {
$GLOBALS['TSFE']->fe_user->user = [];
}
EXT:vhs:
-
$userIsLoggedIn = (is_array($GLOBALS['TSFE']->fe_user->user));