Project

General

Profile

Actions

Story #88348

closed

Respect visibility aspect in QueryBuilder

Added by Stefan Froemken over 5 years ago. Updated over 4 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Database API (Doctrine DBAL)
Target version:
-
Start date:
2019-05-14
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
9
PHP Version:
7.2
Tags:
Sprint Focus:

Description

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?

Stefan


Related issues 1 (0 open1 closed)

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

Actions
Actions #1

Updated by Stefan Froemken over 5 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(
                'visibility',
                'includeHiddenContent',
                false
            );
        } else {
            $showHiddenRecords = (bool)$this->getTypoScriptFrontendController()->showHiddenRecords;
        }

        if ($showHiddenRecords) {
            $queryBuilder->getRestrictions()->removeByType(HiddenRestriction::class);
        }
    }
Actions #2

Updated by Georg Ringer over 5 years ago

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

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

Actions #4

Updated by Stefan Froemken over 4 years 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:
https://github.com/jweiland-net/events2/blob/master/Classes/Service/DatabaseService.php#L549

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

Stefan

Actions #5

Updated by Susanne Moog over 4 years 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()) {
            $queryBuilder->setRestrictions(GeneralUtility::makeInstance(FrontendRestrictionContainer::class));
        }
Actions #6

Updated by Stefan Froemken over 4 years 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:

https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/Database/RestrictionBuilder/Index.html (-> 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

Stefan

Actions #7

Updated by Riccardo De Contardi over 4 years 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

Actions

Also available in: Atom PDF