‪TYPO3CMS  ‪main
TYPO3\CMS\Form\Domain\Runtime\FormRuntime Class Reference
Inheritance diagram for TYPO3\CMS\Form\Domain\Runtime\FormRuntime:
TYPO3\CMS\Form\Domain\Model\Renderable\RootRenderableInterface

Public Member Functions

 __construct (protected readonly ContainerInterface $container, protected readonly ConfigurationManagerInterface $configurationManager, protected readonly HashService $hashService, protected readonly ValidatorResolver $validatorResolver, private readonly Context $context,)
 
 setFormDefinition (FormDefinition $formDefinition)
 
 setRequest (RequestInterface $request)
 
 initialize ()
 
 overrideCurrentPage (int $pageIndex)
 
string null render ()
 
string getIdentifier ()
 
RequestInterface getRequest ()
 
ResponseInterface getResponse ()
 
 canProcessFormSubmission ()
 
 getFormSession ()
 
 getCurrentPage ()
 
 getPreviousPage ()
 
 getNextPage ()
 
 getPreviousEnabledPage ()
 
 getNextEnabledPage ()
 
 getType ()
 
 offsetExists (mixed $identifier)
 
 offsetGet (mixed $identifier)
 
 offsetSet (mixed $identifier, mixed $value)
 
 offsetUnset (mixed $identifier)
 
mixed getElementValue (string $identifier)
 
array Page[] getPages ()
 
 getFormState ()
 
array getRenderingOptions ()
 
string getRendererClassName ()
 
 getLabel ()
 
 getTemplateName ()
 
 getFormDefinition ()
 
SiteLanguage getCurrentSiteLanguage ()
 
 setCurrentSiteLanguage (SiteLanguage $currentSiteLanguage)
 
 getCurrentFinisher ()
 

Public Attributes

const HONEYPOT_NAME_SESSION_IDENTIFIER = 'tx_form_honeypot_name_'
 

Protected Member Functions

 initializeFormSessionFromRequest ()
 
 initializeFormStateFromRequest ()
 
 triggerAfterFormStateInitialized ()
 
 initializeCurrentPageFromRequest ()
 
 initializeHoneypotFromRequest ()
 
 renderHoneypot ()
 
string null getHoneypotNameFromSession (Page $page)
 
 setHoneypotNameInSession (Page $page, string $honeypotName)
 
 isFrontendUserAuthenticated ()
 
 processVariants ()
 
 isAfterLastPage ()
 
 isFirstRequest ()
 
 isPostRequest ()
 
 isRenderedCached ()
 
 processSubmittedFormValues ()
 
 userWentBackToPreviousStep ()
 
 mapAndValidatePage (Page $page)
 
 invokeFinishers ()
 
 initializeCurrentSiteLanguage ()
 
 getConditionResolver ()
 
 getFrontendUser ()
 
 isRenderableEnabled (RenderableInterface $renderable)
 

Protected Attributes

FormDefinition $formDefinition
 
RequestInterface $request
 
ResponseInterface $response
 
FormState $formState
 
FormSession null $formSession
 
Page null $currentPage
 
Page $lastDisplayedPage
 
SiteLanguage $currentSiteLanguage
 
FinisherInterface $currentFinisher
 

Detailed Description

This class implements the runtime logic of a form, i.e. deciding which page is shown currently, what the current values of the form are, trigger validation and property mapping.

You generally receive an instance of this class by calling \TYPO3\CMS\Form\Domain\Model\FormDefinition::bind.

Rendering a Form

That's easy, just call render() on the FormRuntime:

/—code php $form = $formDefinition->bind($request); $renderedForm = $form->render(); ---

Accessing Form Values

In order to get the values the user has entered into the form, you can access this object like an array: If a form field with the identifier firstName exists, you can do $form['firstName'] to retrieve its current value.

You can also set values in the same way.

Rendering Internals

The FormRuntime asks the FormDefinition about the configured Renderer which should be used (\TYPO3\CMS\Form\Domain\Model\FormDefinition::getRendererClassName), and then trigger render() on this Renderer.

This makes it possible to declaratively define how a form should be rendered.

Scope: frontend This class is NOT meant to be sub classed by developers.

High cohesion to FormDefinition, may change any time

Todo:
‪: Declare final in v12

Definition at line 105 of file FormRuntime.php.

Constructor & Destructor Documentation

◆ __construct()

TYPO3\CMS\Form\Domain\Runtime\FormRuntime::__construct ( protected readonly ContainerInterface  $container,
protected readonly ConfigurationManagerInterface  $configurationManager,
protected readonly HashService  $hashService,
protected readonly ValidatorResolver  $validatorResolver,
private readonly Context  $context 
)

Definition at line 154 of file FormRuntime.php.

Member Function Documentation

◆ canProcessFormSubmission()

TYPO3\CMS\Form\Domain\Runtime\FormRuntime::canProcessFormSubmission ( )

Only process values if there is a post request and if the surrounding content object is uncached. Is this not the case, all possible submitted values will be discarded and the first form step will be shown with an empty form state.

Definition at line 737 of file FormRuntime.php.

References TYPO3\CMS\Form\Domain\Runtime\FormRuntime\isPostRequest(), and TYPO3\CMS\Form\Domain\Runtime\FormRuntime\isRenderedCached().

Referenced by TYPO3\CMS\Form\Mvc\Property\PropertyMappingConfiguration\adjustPropertyMappingForFileUploadsAtRuntime(), TYPO3\CMS\Form\Domain\Runtime\FormRuntime\initialize(), TYPO3\CMS\Form\Domain\Runtime\FormRuntime\initializeFormSessionFromRequest(), and TYPO3\CMS\Form\Domain\Runtime\FormRuntime\initializeFormStateFromRequest().

◆ getConditionResolver()

◆ getCurrentFinisher()

TYPO3\CMS\Form\Domain\Runtime\FormRuntime::getCurrentFinisher ( )

Reference to the current running finisher

Definition at line 1043 of file FormRuntime.php.

References TYPO3\CMS\Form\Domain\Runtime\FormRuntime\$currentFinisher.

Referenced by TYPO3\CMS\Form\Domain\Runtime\FormRuntime\getConditionResolver().

◆ getCurrentPage()

TYPO3\CMS\Form\Domain\Runtime\FormRuntime::getCurrentPage ( )

Returns the currently selected page

Definition at line 753 of file FormRuntime.php.

References TYPO3\CMS\Form\Domain\Runtime\FormRuntime\$currentPage.

Referenced by TYPO3\CMS\Form\Domain\Runtime\FormRuntime\getConditionResolver().

◆ getCurrentSiteLanguage()

SiteLanguage TYPO3\CMS\Form\Domain\Runtime\FormRuntime::getCurrentSiteLanguage ( )

Get the current site language configuration.

Returns
‪SiteLanguage

Definition at line 995 of file FormRuntime.php.

References TYPO3\CMS\Form\Domain\Runtime\FormRuntime\$currentSiteLanguage.

◆ getElementValue()

mixed TYPO3\CMS\Form\Domain\Runtime\FormRuntime::getElementValue ( string  $identifier)

Returns the value of the specified element

Returns
‪mixed

Definition at line 920 of file FormRuntime.php.

References TYPO3\CMS\Webhooks\Message\$identifier.

Referenced by TYPO3\CMS\Form\Domain\Runtime\FormRuntime\offsetExists(), and TYPO3\CMS\Form\Domain\Runtime\FormRuntime\offsetGet().

◆ getFormDefinition()

◆ getFormSession()

TYPO3\CMS\Form\Domain\Runtime\FormRuntime::getFormSession ( )

◆ getFormState()

TYPO3\CMS\Form\Domain\Runtime\FormRuntime::getFormState ( )

◆ getFrontendUser()

TYPO3\CMS\Form\Domain\Runtime\FormRuntime::getFrontendUser ( )
protected

◆ getHoneypotNameFromSession()

◆ getIdentifier()

◆ getLabel()

TYPO3\CMS\Form\Domain\Runtime\FormRuntime::getLabel ( )

Get the label which shall be displayed next to the form element

Implements TYPO3\CMS\Form\Domain\Model\Renderable\RootRenderableInterface.

Definition at line 969 of file FormRuntime.php.

◆ getNextEnabledPage()

TYPO3\CMS\Form\Domain\Runtime\FormRuntime::getNextEnabledPage ( )

Returns the next enabled page of the currently selected one or NULL if there is no next page

Definition at line 813 of file FormRuntime.php.

Referenced by TYPO3\CMS\Form\Domain\Runtime\FormRuntime\initializeCurrentPageFromRequest().

◆ getNextPage()

TYPO3\CMS\Form\Domain\Runtime\FormRuntime::getNextPage ( )

Returns the next page of the currently selected one or NULL if there is no next page

Definition at line 773 of file FormRuntime.php.

References TYPO3\CMS\Form\Domain\Model\Renderable\AbstractRenderable\getIndex().

◆ getPages()

array Page [] TYPO3\CMS\Form\Domain\Runtime\FormRuntime::getPages ( )
Returns
‪array|Page[] The Form's pages in the correct order

Definition at line 932 of file FormRuntime.php.

◆ getPreviousEnabledPage()

TYPO3\CMS\Form\Domain\Runtime\FormRuntime::getPreviousEnabledPage ( )

Returns the previous enabled page of the currently selected one or NULL if there is no previous page

Definition at line 786 of file FormRuntime.php.

References TYPO3\CMS\Form\Domain\Model\Renderable\AbstractRenderable\getIndex().

Referenced by TYPO3\CMS\Form\Domain\Runtime\FormRuntime\initializeCurrentPageFromRequest().

◆ getPreviousPage()

TYPO3\CMS\Form\Domain\Runtime\FormRuntime::getPreviousPage ( )

Returns the previous page of the currently selected one or NULL if there is no previous page

Definition at line 761 of file FormRuntime.php.

References TYPO3\CMS\Form\Domain\Model\Renderable\AbstractRenderable\getIndex().

◆ getRendererClassName()

string TYPO3\CMS\Form\Domain\Runtime\FormRuntime::getRendererClassName ( )

Get the renderer class name to be used to display this renderable; must implement RendererInterface

Returns
‪string the renderer class name

Implements TYPO3\CMS\Form\Domain\Model\Renderable\RootRenderableInterface.

Definition at line 961 of file FormRuntime.php.

◆ getRenderingOptions()

array TYPO3\CMS\Form\Domain\Runtime\FormRuntime::getRenderingOptions ( )

◆ getRequest()

RequestInterface TYPO3\CMS\Form\Domain\Runtime\FormRuntime::getRequest ( )

Get the request this object is bound to.

This is mostly relevant inside Finishers, where you f.e. want to redirect the user to another page.

Returns
‪RequestInterface The request this object is bound to

Definition at line 711 of file FormRuntime.php.

References TYPO3\CMS\Form\Domain\Runtime\FormRuntime\$request.

Referenced by TYPO3\CMS\Form\Domain\Runtime\FormRuntime\getConditionResolver(), and TYPO3\CMS\Form\Domain\Runtime\FormRuntime\isPostRequest().

◆ getResponse()

ResponseInterface TYPO3\CMS\Form\Domain\Runtime\FormRuntime::getResponse ( )

Get the response this object is bound to.

This is mostly relevant inside Finishers, where you f.e. want to set response headers or output content.

Returns
‪ResponseInterface the response this object is bound to

Definition at line 724 of file FormRuntime.php.

References TYPO3\CMS\Form\Domain\Runtime\FormRuntime\$response.

◆ getTemplateName()

TYPO3\CMS\Form\Domain\Runtime\FormRuntime::getTemplateName ( )

Get the template name of the renderable

Definition at line 977 of file FormRuntime.php.

◆ getType()

TYPO3\CMS\Form\Domain\Runtime\FormRuntime::getType ( )

Abstract "type" of this Renderable. Is used during the rendering process to determine the template file or the View PHP class being used to render the particular element.

Implements TYPO3\CMS\Form\Domain\Model\Renderable\RootRenderableInterface.

Definition at line 845 of file FormRuntime.php.

◆ initialize()

◆ initializeCurrentPageFromRequest()

TYPO3\CMS\Form\Domain\Runtime\FormRuntime::initializeCurrentPageFromRequest ( )
protected

◆ initializeCurrentSiteLanguage()

TYPO3\CMS\Form\Domain\Runtime\FormRuntime::initializeCurrentSiteLanguage ( )
protected

Initialize the SiteLanguage object. This is mainly used by the condition matcher.

Definition at line 1017 of file FormRuntime.php.

Referenced by TYPO3\CMS\Form\Domain\Runtime\FormRuntime\initialize().

◆ initializeFormSessionFromRequest()

TYPO3\CMS\Form\Domain\Runtime\FormRuntime::initializeFormSessionFromRequest ( )
protected
Todo:
FormRuntime::$formSession is still vulnerable to session fixation unless a real cookie-based process is used

Definition at line 203 of file FormRuntime.php.

References TYPO3\CMS\Form\Domain\Runtime\FormRuntime\canProcessFormSubmission().

Referenced by TYPO3\CMS\Form\Domain\Runtime\FormRuntime\initialize().

◆ initializeFormStateFromRequest()

TYPO3\CMS\Form\Domain\Runtime\FormRuntime::initializeFormStateFromRequest ( )
protected

Initializes the current state of the form, based on the request

Exceptions
BadRequestException

Definition at line 221 of file FormRuntime.php.

References TYPO3\CMS\Form\Domain\Runtime\FormRuntime\canProcessFormSubmission(), and TYPO3\CMS\Extbase\Security\prefix.

Referenced by TYPO3\CMS\Form\Domain\Runtime\FormRuntime\initialize().

◆ initializeHoneypotFromRequest()

TYPO3\CMS\Form\Domain\Runtime\FormRuntime::initializeHoneypotFromRequest ( )
protected

◆ invokeFinishers()

TYPO3\CMS\Form\Domain\Runtime\FormRuntime::invokeFinishers ( )
protected

Executes all finishers of this form

Definition at line 660 of file FormRuntime.php.

References $output, and TYPO3\CMS\Form\Domain\Runtime\FormRuntime\processVariants().

Referenced by TYPO3\CMS\Form\Domain\Runtime\FormRuntime\render().

◆ isAfterLastPage()

TYPO3\CMS\Form\Domain\Runtime\FormRuntime::isAfterLastPage ( )
protected

Returns TRUE if the last page of the form has been submitted, otherwise FALSE

Definition at line 470 of file FormRuntime.php.

Referenced by TYPO3\CMS\Form\Domain\Runtime\FormRuntime\render(), TYPO3\CMS\Form\Domain\Runtime\FormRuntime\renderHoneypot(), and TYPO3\CMS\Form\Domain\Runtime\FormRuntime\userWentBackToPreviousStep().

◆ isFirstRequest()

TYPO3\CMS\Form\Domain\Runtime\FormRuntime::isFirstRequest ( )
protected

◆ isFrontendUserAuthenticated()

TYPO3\CMS\Form\Domain\Runtime\FormRuntime::isFrontendUserAuthenticated ( )
protected

Necessary to know if honeypot information should be stored in the user session info, or in the anonymous session.

Definition at line 446 of file FormRuntime.php.

Referenced by TYPO3\CMS\Form\Domain\Runtime\FormRuntime\getHoneypotNameFromSession(), and TYPO3\CMS\Form\Domain\Runtime\FormRuntime\setHoneypotNameInSession().

◆ isPostRequest()

TYPO3\CMS\Form\Domain\Runtime\FormRuntime::isPostRequest ( )
protected

◆ isRenderableEnabled()

◆ isRenderedCached()

TYPO3\CMS\Form\Domain\Runtime\FormRuntime::isRenderedCached ( )
protected

Determine whether the surrounding content object is cached. If no surrounding content object can be found (which would be strange) we assume a cached request for safety which means that an empty form will be rendered.

Definition at line 494 of file FormRuntime.php.

References TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer\OBJECTTYPE_USER.

Referenced by TYPO3\CMS\Form\Domain\Runtime\FormRuntime\canProcessFormSubmission().

◆ mapAndValidatePage()

◆ offsetExists()

TYPO3\CMS\Form\Domain\Runtime\FormRuntime::offsetExists ( mixed  $identifier)
Parameters
string$identifier

Definition at line 854 of file FormRuntime.php.

References TYPO3\CMS\Webhooks\Message\$identifier, and TYPO3\CMS\Form\Domain\Runtime\FormRuntime\getElementValue().

◆ offsetGet()

TYPO3\CMS\Form\Domain\Runtime\FormRuntime::offsetGet ( mixed  $identifier)
Parameters
string$identifier

Definition at line 882 of file FormRuntime.php.

References TYPO3\CMS\Webhooks\Message\$identifier, and TYPO3\CMS\Form\Domain\Runtime\FormRuntime\getElementValue().

◆ offsetSet()

TYPO3\CMS\Form\Domain\Runtime\FormRuntime::offsetSet ( mixed  $identifier,
mixed  $value 
)
Parameters
string$identifier

Definition at line 899 of file FormRuntime.php.

References TYPO3\CMS\Webhooks\Message\$identifier.

◆ offsetUnset()

TYPO3\CMS\Form\Domain\Runtime\FormRuntime::offsetUnset ( mixed  $identifier)
Parameters
string$identifier

Definition at line 909 of file FormRuntime.php.

References TYPO3\CMS\Webhooks\Message\$identifier.

◆ overrideCurrentPage()

TYPO3\CMS\Form\Domain\Runtime\FormRuntime::overrideCurrentPage ( int  $pageIndex)

Override the current page taken from the request, rendering the page with index $pageIndex instead.

This is typically not needed in production code, but it is very helpful when displaying some kind of "preview" of the form (e.g. form editor).

Parameters
int$pageIndex

Definition at line 624 of file FormRuntime.php.

◆ processSubmittedFormValues()

TYPO3\CMS\Form\Domain\Runtime\FormRuntime::processSubmittedFormValues ( )
protected

◆ processVariants()

◆ render()

string null TYPO3\CMS\Form\Domain\Runtime\FormRuntime::render ( )

Render this form.

Returns
‪string|null rendered form
Exceptions
RenderingException

Definition at line 635 of file FormRuntime.php.

References TYPO3\CMS\Form\Domain\Runtime\FormRuntime\invokeFinishers(), TYPO3\CMS\Form\Domain\Runtime\FormRuntime\isAfterLastPage(), and TYPO3\CMS\Form\Domain\Runtime\FormRuntime\processVariants().

◆ renderHoneypot()

◆ setCurrentSiteLanguage()

TYPO3\CMS\Form\Domain\Runtime\FormRuntime::setCurrentSiteLanguage ( SiteLanguage  $currentSiteLanguage)

Override the the current site language configuration.

This is typically not needed in production code, but it is very helpful when displaying some kind of "preview" of the form (e.g. form editor).

Parameters
SiteLanguage$currentSiteLanguage

Definition at line 1008 of file FormRuntime.php.

References TYPO3\CMS\Form\Domain\Runtime\FormRuntime\$currentSiteLanguage.

◆ setFormDefinition()

TYPO3\CMS\Form\Domain\Runtime\FormRuntime::setFormDefinition ( FormDefinition  $formDefinition)

◆ setHoneypotNameInSession()

◆ setRequest()

TYPO3\CMS\Form\Domain\Runtime\FormRuntime::setRequest ( RequestInterface  $request)

◆ triggerAfterFormStateInitialized()

TYPO3\CMS\Form\Domain\Runtime\FormRuntime::triggerAfterFormStateInitialized ( )
protected

Definition at line 241 of file FormRuntime.php.

References $GLOBALS.

Referenced by TYPO3\CMS\Form\Domain\Runtime\FormRuntime\initialize().

◆ userWentBackToPreviousStep()

TYPO3\CMS\Form\Domain\Runtime\FormRuntime::userWentBackToPreviousStep ( )
protected

Member Data Documentation

◆ $currentFinisher

FinisherInterface TYPO3\CMS\Form\Domain\Runtime\FormRuntime::$currentFinisher
protected

Reference to the current running finisher

Definition at line 152 of file FormRuntime.php.

Referenced by TYPO3\CMS\Form\Domain\Runtime\FormRuntime\getCurrentFinisher().

◆ $currentPage

Page null TYPO3\CMS\Form\Domain\Runtime\FormRuntime::$currentPage
protected

The current page is the page which will be displayed to the user during rendering.

If $currentPage is NULL, the last page has been submitted and finishing actions need to take place. You should use $this->isAfterLastPage() instead of explicitly checking for NULL.

Definition at line 133 of file FormRuntime.php.

Referenced by TYPO3\CMS\Form\Domain\Runtime\FormRuntime\getCurrentPage().

◆ $currentSiteLanguage

SiteLanguage TYPO3\CMS\Form\Domain\Runtime\FormRuntime::$currentSiteLanguage
protected

◆ $formDefinition

FormDefinition TYPO3\CMS\Form\Domain\Runtime\FormRuntime::$formDefinition
protected

◆ $formSession

FormSession null TYPO3\CMS\Form\Domain\Runtime\FormRuntime::$formSession
protected

Individual unique random form session identifier valid for current user session. This value is not persisted server-side.

Definition at line 122 of file FormRuntime.php.

Referenced by TYPO3\CMS\Form\Domain\Runtime\FormRuntime\getFormSession().

◆ $formState

FormState TYPO3\CMS\Form\Domain\Runtime\FormRuntime::$formState
protected

◆ $lastDisplayedPage

Page TYPO3\CMS\Form\Domain\Runtime\FormRuntime::$lastDisplayedPage
protected

Reference to the page which has been shown on the last request (i.e. we have to handle the submitted data from lastDisplayedPage)

Definition at line 140 of file FormRuntime.php.

Referenced by TYPO3\CMS\Form\Domain\Runtime\FormRuntime\processSubmittedFormValues().

◆ $request

RequestInterface TYPO3\CMS\Form\Domain\Runtime\FormRuntime::$request
protected

◆ $response

ResponseInterface TYPO3\CMS\Form\Domain\Runtime\FormRuntime::$response
protected

◆ HONEYPOT_NAME_SESSION_IDENTIFIER

const TYPO3\CMS\Form\Domain\Runtime\FormRuntime::HONEYPOT_NAME_SESSION_IDENTIFIER = 'tx_form_honeypot_name_'

Definition at line 107 of file FormRuntime.php.