Story #88348

Respect visibility aspect in QueryBuilder

Added by Stefan Froemken over 2 years ago. Updated over 1 year ago.

Should have
Database API (Doctrine DBAL)
Target version:
Start date:
Due date:
% Done:


Estimated time:
TYPO3 Version:
PHP Version:
Sprint Focus:


Hello Core-Team,

I'm using extbase with my own Query based on Doctrine QueryBuilder.
If config.admPanel is activated and checkbox showHiddenRecords is set, hidden records will not be shown in frontend.

Is it my job to implement correct handling of showHiddenRecords or is it a missing feature somewhere in the DefaultRestrictionContainer?


Related issues

Related to TYPO3 Core - Bug #86653: Preview of page, with "show", not working when starttime is setClosed2018-10-14


Updated by Stefan Froemken over 2 years ago

My current solution:

     * Working with own QueryBuilder queries does not respect showHiddenContent settings of TYPO3, that's why
     * we have to manually remove Hidden constraint from restriction container.
     * @param QueryBuilder $queryBuilder
    public function addVisibilityConstraintToQuery(QueryBuilder $queryBuilder)
        if (version_compare(TYPO3_branch, '9.4', '>=')) {
            $context = GeneralUtility::makeInstance(Context::class);
            $showHiddenRecords = (bool)$context->getPropertyFromAspect(
        } else {
            $showHiddenRecords = (bool)$this->getTypoScriptFrontendController()->showHiddenRecords;

        if ($showHiddenRecords) {

Updated by Georg Ringer over 2 years ago

  • Related to Bug #86653: Preview of page, with "show", not working when starttime is set added

Updated by Susanne Moog over 1 year ago

  • Status changed from New to Needs Feedback

Can you please check if the bug still exists and provide an example how to reproduce?

The visibility aspect is implemented in the \TYPO3\CMS\Core\Database\Query\Restriction\FrontendRestrictionContainer (note the "Frontend") and should be taken into account if used.


Updated by Stefan Froemken over 1 year ago

Problem still exists. If you want to test that, you can install events2 and create a hidden and a visible event. Go into FE and it will work. Of cause, as I have added a patch for that into events2.
Please remove the body of this method to get the original Core handling:

As you will see, the hidden record will never be visible in FE.



Updated by Susanne Moog over 1 year ago

Ok, maybe I should have asked more precisely:

From what I can see in the code, where do you add the Frontend restrictions?

What I'm missing is: `$queryBuilder->setRestrictions(GeneralUtility::makeInstance(FrontendRestrictionContainer::class));`

That's what I meant with my previous comment. If you do not take care, you only get the DefaultRestrictionContainer - which does not care about frontend related settings in TSFE. If you are in frontend context, use the FrontendRestrictionContainer.

For example, this is how extbase does it:

        $queryBuilder = $this->connectionPool->getQueryBuilderForTable($tableName);
        if ($this->environmentService->isEnvironmentInFrontendMode()) {

Updated by Stefan Froemken over 1 year ago

Hello Susi,

thank you for that hint. I remember that I have debugged the new Doctrine thing at a very early state where TYPO3 Core adopt the correct RestrictionContainer for the developer automatically: (-> first blue note)

I didn't noticed that this behavior was changed in the past.

OK...much to do. I have to check various extensions, where I have build my own Queries for FE with TYPO3's QueryBuilder.

So, yes, this ticket can be closed now, as my problem is solved with FrontendRestrictionContainer



Updated by Riccardo De Contardi over 1 year ago

  • Status changed from Needs Feedback to Closed

@Stefan Froemken thank you for your reply; closing it

if you think that this is the wrong decision, please reopen it or ping me on Slack

Also available in: Atom PDF