TYPO3CMS-Reference-CoreApi
TYPO3CMS-Reference-CoreApi copied to clipboard
[DOCS] Document request independence for BaseVariants conditions
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.
(would like to get feedback of Benni oder Georg before merging this, to confirm I understood this properly)
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.
I would suggest to put it on DRAFT until done so we dont have to keep coming back to it
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
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
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 how shall we proceed here?
Converted to draft for my pile of shame