Bug #85310

$GLOBALS['BE_USER] is null causes Errors in FE

Added by Julian Stelzer about 4 years ago. Updated almost 4 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
-
Target version:
Start date:
2018-06-19
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
9
PHP Version:
7.2
Tags:
Complexity:
Is Regression:
Sprint Focus:

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.

Related issues

Related to TYPO3 Core - Task #82497: Streamline \TYPO3\CMS\Backend\Utility\BackendUtility::getPagesTSconfigClosedAlexander Schnitzler2017-09-17

Actions
#1

Updated by Julian Stelzer about 4 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
#2

Updated by Georg Ringer about 4 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.

#3

Updated by Julian Stelzer about 4 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.

#4

Updated by Jan Schröder about 4 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 :-(

#5

Updated by Julian Stelzer about 4 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.

#6

Updated by Sinisa Mitrovic almost 4 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();
        }
#7

Updated by sonal vadhavana almost 4 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();
        }
#8

Updated by Thomas Kieslich almost 4 years ago

If this doesn't work try to set enabledBeUserIPLock to false. checkLockToIP() is called before your own Controller.

#9

Updated by Susanne Moog almost 4 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.

#10

Updated by Benni Mack almost 4 years ago

  • Related to Task #82497: Streamline \TYPO3\CMS\Backend\Utility\BackendUtility::getPagesTSconfig added
#11

Updated by Gerrit Code Review almost 4 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

#12

Updated by Benni Mack almost 4 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
#13

Updated by Benni Mack almost 4 years ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF