Bug #85310
closed$GLOBALS['BE_USER] is null causes Errors in FE
100%
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.
Updated by Julian Stelzer over 6 years ago
- Project changed from 9 to TYPO3 Core
- Target version set to 9.4
- TYPO3 Version set to 9
- PHP Version set to 7.2
Updated by Georg Ringer over 6 years ago
- 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.
Updated by Julian Stelzer over 6 years ago
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.
Updated by Jan Schröder over 6 years ago
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 :-(
Updated by Julian Stelzer over 6 years ago
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.
Updated by Sinisa Mitrovic over 6 years ago
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();
}
Updated by sonal vadhavana over 6 years ago
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(); }
Updated by Thomas Kieslich over 6 years ago
If this doesn't work try to set enabledBeUserIPLock to false. checkLockToIP() is called before your own Controller.
Updated by Susanne Moog about 6 years ago
- 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.
Updated by Benni Mack about 6 years ago
- Related to Task #82497: Streamline \TYPO3\CMS\Backend\Utility\BackendUtility::getPagesTSconfig added
Updated by Gerrit Code Review about 6 years ago
- Status changed from Accepted to Under Review
Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58174
Updated by Benni Mack about 6 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset 3260e09382068949e03cf4d6ca2a497275c2671e.