Project

General

Profile

Actions

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.

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 1 (0 open1 closed)

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

Actions
Actions #1

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
Actions #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.

Actions #3

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.

Actions #4

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 :-(

Actions #5

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.

Actions #6

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();
        }
Actions #7

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();
        }
Actions #8

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.

Actions #9

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.

Actions #10

Updated by Benni Mack about 6 years ago

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

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

Actions #12

Updated by Benni Mack about 6 years ago

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

Updated by Benni Mack about 6 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF