TYPO3CMS-Reference-CoreApi icon indicating copy to clipboard operation
TYPO3CMS-Reference-CoreApi copied to clipboard

[DOCS] Document request independence for BaseVariants conditions

Open garvinhicking opened this issue 6 months ago • 8 comments

See https://forge.typo3.org/issues/106696 - conditions must be request independant.

Thus, "ip()" and "traverse(request)" examples are removed and it is stated that request dependency must be avoided. Otherwise, custom condition/expression providers must be utilized.

garvinhicking avatar May 28 '25 07:05 garvinhicking

(would like to get feedback of Benni oder Georg before merging this, to confirm I understood this properly)

garvinhicking avatar May 28 '25 07:05 garvinhicking

I will need to alter the traverse() example and check for a version that does not use request. I do not have an idea yet.

fe-hicking avatar Jun 07 '25 10:06 fe-hicking

I would suggest to put it on DRAFT until done so we dont have to keep coming back to it

linawolf avatar Jun 07 '25 13:06 linawolf

I'd rather to put in a todo and merge it than set to draft; I'll forget drafts. ;)

Please leave it open for the codesprint

fe-hicking avatar Jun 07 '25 14:06 fe-hicking

Hi @garvinhicking

please have a look where RequestWrapper is assigned to in core. This is done just somewhere in EXT:form and in IncludeTreeConditionMatcherVisitor which is only loaded in TypoScript context. So, because TypoScript is not loaded in SiteResolver, the RequestWrapper with very specific methods to request object are not available. Implementation seems to be very easy:

        // If a request is given, make sure it is an instance of RequestWrapper,
        // if not, create an instance from ServerRequestInterface and set it.
        if (isset($variables['request']) && !($variables['request'] instanceof RequestWrapper)) {
            $variables['request'] = new RequestWrapper($variables['request']);
        } elseif (!isset($variables['request'])) {
            $variables['request'] = new RequestWrapper(null);
        }

All these methods are working in earlier TYPO3 versions. It was removed in TYPO3 ~11 to prevent access to ALL request data. As a replacement the new RequestWrapper was introduced, which just allows specific function calls to request object. getNormalizedParams is still there and could be used, if core can add just one simple line of code:

        $this->expressionLanguageVariables = [
            'applicationContext' => (string)Environment::getContext(),
            'typo3' => $typo3,
            'date' => $context->getAspect('date'),
            'request' => new RequestWrapper($GLOBALS['TYPO3_REQUEST'] ?? null),
            'features' => $features,
        ];

Sure...the request is not 100% initialized. It does not have frontend_typoscript, page, router. But to access ip, parameters for GET and POST it's enough.

What do you think?

Stefan

froemken avatar Jun 12 '25 19:06 froemken

Thanks - I thought the typoscript would be cached (and not centrally not "not available at all").

I would have to dive deeper now thanks to your ideas. I doubt though the core will add a TYPO3_REQUEST reference here, because I think the idea is to drop this at some point and would add a burden then.

Creatting aa reauest from $_SERVER or so might also kill some context... so, the request would need to be really passed as a variable in here. And there I do not know yet how/if that would be possible. Only looking at it superficially, and I see there is work to be done here.

garvinhicking avatar Jun 12 '25 20:06 garvinhicking

@garvinhicking how shall we proceed here?

linawolf avatar Oct 03 '25 05:10 linawolf

Converted to draft for my pile of shame

garvinhicking avatar Oct 03 '25 10:10 garvinhicking