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.

Certifications & exams

Which exam comes next?

You can already practise for 19 exams, and 21 are up for a vote. See all certifications with their official information, cast your vote or suggest your exam.

See all certifications