Architecture and request · Question 9 of 12
A custom ViewHelper needs the current request, for example to read the site. How does it get it in TYPO3 v14?
1 answer is correct. Medium
Show answer
Answer
- C $this->renderingContext->getAttribute(ServerRequestInterface::class)
Explanation
The RenderingContextFactory stores the request as an attribute of the RenderingContext, and the Core reads it from there itself, e.g. in f:image and f:flashMessages. A ViewHelper therefore gets it via $this->renderingContext->getAttribute(ServerRequestInterface::class) and can then call e.g. $request->getAttribute('site'). $GLOBALS['TYPO3_REQUEST'] is a leftover the Core is phasing out. The request is not a service of the DI container, so makeInstance does not return it.