Bug #85310
closed
$GLOBALS['BE_USER] is null causes Errors in FE
Added by Julian Stelzer over 6 years ago.
Updated about 6 years ago.
Description
Call to a member function getTSConfig() on null
Error thrown in file
../typo3/sysext/backend/Classes/Utility/BackendUtility.php in line 873.
Trying to save data of a form in my database in Frontend.
The error comes from this line:
$userTSconfig = static::getBackendUserAuthentication()->getTSConfig() ?? [];
static::getBackendUserAuthentication() is null.
- Project changed from 9 to TYPO3 Core
- Target version set to 9.4
- TYPO3 Version set to 9
- PHP Version set to 7.2
- Status changed from New to Needs Feedback
BackendUtility
is for the backend as the name suggests. what are you doing exactly to get this error? you can also initialize the $GLOBALS['BE_USER']
yourself in the FE.
Georg Ringer wrote:
BackendUtility
is for the backend as the name suggests. what are you doing exactly to get this error? you can also initialize the $GLOBALS['BE_USER']
yourself in the FE.
I try to save some modeldata in my FE with the add-function of \TYPO3\CMS\Extbase\Persistence\Repository. I dont want to use the $GLOBALS['BE_USER'] or the BackendUtility-Class on my own, but TYPO3 is doing that for me and it causes this error. The same function works great in TYPO3 7.6.
In TYPO3 8.x the function getTSConfig work without and Backend Login.
Since TYPO3 9 the getTSConfig is not working anymore in Frontend Context.
Is there a way to create the missing $GLOBALS['BE_USER'] or is there another way to get the TSConfig in frontend context?
The breaking change is not documented and broke the gridelements extension :-(
It currently breaks all extensions, which write from Frontend into Database and use the repository methods.
Quickfix:
$userTSconfig = [];
if( static::getBackendUserAuthentication() ){
$userTSconfig = static::getBackendUserAuthentication()->getTSConfig() ?? [];
}
//$userTSconfig = static::getBackendUserAuthentication()->getTSConfig() ?? [];
But it should be fixed soon.
Another quick fix can be initializing BE User before fetching getPagesTSconfig.
if($GLOBALS['BE_USER'] === null) {
$GLOBALS['BE_USER'] = GeneralUtility::makeInstance('TYPO3\CMS\Core\Authentication\BackendUserAuthentication');
$GLOBALS['BE_USER']->start();
}
yes, this solution works fine but needs to improve by this one:
First include the namespace and then write code: Otherwise give deprecation error.
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
if($GLOBALS['BE_USER'] === null) {
$GLOBALS['BE_USER'] = GeneralUtility::makeInstance(BackendUserAuthentication::class);
$GLOBALS['BE_USER']->start();
}
If this doesn't work try to set enabledBeUserIPLock to false. checkLockToIP() is called before your own Controller.
- Status changed from Needs Feedback to Accepted
Problem seems to be that `\TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbBackend::clearPageCache` calls `$pageTS = BackendUtility::getPagesTSconfig($storagePage)` in case of write operations with extbase (delete, update, add), which in turn needs a valid backend user.
- Related to Task #82497: Streamline \TYPO3\CMS\Backend\Utility\BackendUtility::getPagesTSconfig added
- Status changed from Accepted to Under Review
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
- Status changed from Resolved to Closed
Also available in: Atom
PDF