‪TYPO3CMS  11.5
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 (ContainerInterface $container, ObjectManagerInterface $objectManager, ConfigurationManagerInterface $configurationManager, HashService $hashService)
 
 setFormDefinition (FormDefinition $formDefinition)
 
 setRequest (Request $request)
 
 initialize ()
 
 overrideCurrentPage (int $pageIndex)
 
string null render ()
 
string getIdentifier ()
 
Request getRequest ()
 
ResponseInterface getResponse ()
 
bool canProcessFormSubmission ()
 
FormSession null getFormSession ()
 
Page null getCurrentPage ()
 
Page null getPreviousPage ()
 
Page null getNextPage ()
 
Page null getPreviousEnabledPage ()
 
Page null getNextEnabledPage ()
 
string getType ()
 
bool offsetExists ($identifier)
 
mixed offsetGet ($identifier)
 
 offsetSet ($identifier, $value)
 
 offsetUnset ($identifier)
 
mixed getElementValue (string $identifier)
 
array Page[] getPages ()
 
FormState null getFormState ()
 
array getRenderingOptions ()
 
string getRendererClassName ()
 
string getLabel ()
 
string getTemplateName ()
 
FormDefinition getFormDefinition ()
 
SiteLanguage getCurrentSiteLanguage ()
 
 setCurrentSiteLanguage (SiteLanguage $currentSiteLanguage)
 
FinisherInterface null 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)
 
bool isFrontendUserAuthenticated ()
 
 processVariants ()
 
bool isAfterLastPage ()
 
bool isFirstRequest ()
 
bool isPostRequest ()
 
bool isRenderedCached ()
 
 processSubmittedFormValues ()
 
bool userWentBackToPreviousStep ()
 
Result mapAndValidatePage (Page $page)
 
string invokeFinishers ()
 
ControllerContext getControllerContext ()
 
 initializeCurrentSiteLanguage ()
 
Resolver getConditionResolver ()
 
FrontendUserAuthentication getFrontendUser ()
 
TypoScriptFrontendController null getTypoScriptFrontendController ()
 

Protected Attributes

ContainerInterface $container
 
ObjectManagerInterface $objectManager
 
FormDefinition $formDefinition = null
 
Request $request = null
 
ResponseInterface $response
 
HashService $hashService
 
ConfigurationManagerInterface $configurationManager
 
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 108 of file FormRuntime.php.

Constructor & Destructor Documentation

◆ __construct()

TYPO3\CMS\Form\Domain\Runtime\FormRuntime::__construct ( ContainerInterface  $container,
ObjectManagerInterface  $objectManager,
ConfigurationManagerInterface  $configurationManager,
HashService  $hashService 
)

Member Function Documentation

◆ canProcessFormSubmission()

bool 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.

Returns
‪bool

Definition at line 776 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()

◆ getControllerContext()

ControllerContext TYPO3\CMS\Form\Domain\Runtime\FormRuntime::getControllerContext ( )
protected
Returns
‪ControllerContext
Deprecated:
‪since v11, will be removed with v12.

Definition at line 894 of file FormRuntime.php.

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

◆ getCurrentFinisher()

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

Reference to the current running finisher

Returns
‪FinisherInterface|null

Definition at line 1138 of file FormRuntime.php.

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

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

◆ getCurrentPage()

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

Returns the currently selected page

Returns
‪Page|null

Definition at line 795 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 1075 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

Parameters
string$identifier
Returns
‪mixed

Definition at line 993 of file FormRuntime.php.

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

◆ getFormDefinition()

FormDefinition TYPO3\CMS\Form\Domain\Runtime\FormRuntime::getFormDefinition ( )

◆ getFormSession()

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

◆ getFormState()

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

◆ getFrontendUser()

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

◆ getHoneypotNameFromSession()

◆ getIdentifier()

◆ getLabel()

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

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

Returns
‪string

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

Definition at line 1045 of file FormRuntime.php.

◆ getNextEnabledPage()

Page null 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

Returns
‪Page|null

Definition at line 863 of file FormRuntime.php.

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

◆ getNextPage()

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

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

Returns
‪Page|null

Definition at line 819 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 1005 of file FormRuntime.php.

◆ getPreviousEnabledPage()

Page null 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

Returns
‪Page|null

Definition at line 834 of file FormRuntime.php.

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

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

◆ getPreviousPage()

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

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

Returns
‪Page|null

Definition at line 805 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 1035 of file FormRuntime.php.

◆ getRenderingOptions()

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

◆ getRequest()

Request 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
‪Request the request this object is bound to

Definition at line 749 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 762 of file FormRuntime.php.

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

◆ getTemplateName()

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

Get the template name of the renderable

Returns
‪string

Definition at line 1055 of file FormRuntime.php.

◆ getType()

string 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.

Returns
‪string

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

Definition at line 912 of file FormRuntime.php.

◆ getTypoScriptFrontendController()

TypoScriptFrontendController null TYPO3\CMS\Form\Domain\Runtime\FormRuntime::getTypoScriptFrontendController ( )
protected
Returns
‪TypoScriptFrontendController|null

Definition at line 1195 of file FormRuntime.php.

References $GLOBALS.

Referenced by TYPO3\CMS\Form\Domain\Runtime\FormRuntime\getFrontendUser(), and TYPO3\CMS\Form\Domain\Runtime\FormRuntime\initializeCurrentSiteLanguage().

◆ 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 1097 of file FormRuntime.php.

References $GLOBALS, and TYPO3\CMS\Form\Domain\Runtime\FormRuntime\getTypoScriptFrontendController().

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 215 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 231 of file FormRuntime.php.

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

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

◆ initializeHoneypotFromRequest()

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

◆ invokeFinishers()

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

◆ isAfterLastPage()

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

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

Returns
‪bool

Definition at line 489 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()

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

◆ isFrontendUserAuthenticated()

bool 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

Returns
‪bool true when a frontend user is logged, otherwise false

Definition at line 461 of file FormRuntime.php.

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

◆ isPostRequest()

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

◆ isRenderedCached()

bool 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.

Todo:
‪: this should be checked against https://forge.typo3.org/issues/91625 as this was fixed differently for UriBuilder
Returns
‪bool

Definition at line 521 of file FormRuntime.php.

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

◆ mapAndValidatePage()

Result TYPO3\CMS\Form\Domain\Runtime\FormRuntime::mapAndValidatePage ( Page  $page)
protected

◆ offsetExists()

bool TYPO3\CMS\Form\Domain\Runtime\FormRuntime::offsetExists (   $identifier)
Parameters
string$identifier
Returns
‪bool
Todo:
‪Set $identifier to mixed type in v12.

Definition at line 923 of file FormRuntime.php.

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

◆ offsetGet()

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

Set $identifier to mixed type in v12.

Set return type to ?mixed in v12.

Definition at line 954 of file FormRuntime.php.

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

◆ offsetSet()

TYPO3\CMS\Form\Domain\Runtime\FormRuntime::offsetSet (   $identifier,
  $value 
)
Parameters
string$identifier
mixed$value
Todo:
‪Set $identifier and $value to mixed type in v12.

Definition at line 972 of file FormRuntime.php.

◆ offsetUnset()

TYPO3\CMS\Form\Domain\Runtime\FormRuntime::offsetUnset (   $identifier)
Parameters
string$identifier
Todo:
‪Set $identifier to mixed type in v12.

Definition at line 982 of file FormRuntime.php.

◆ 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 650 of file FormRuntime.php.

◆ processSubmittedFormValues()

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

◆ processVariants()

◆ render()

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

◆ 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 1088 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 ( Request  $request)

◆ triggerAfterFormStateInitialized()

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

Definition at line 249 of file FormRuntime.php.

References $GLOBALS.

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

◆ userWentBackToPreviousStep()

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

returns TRUE if the user went back to any previous step in the form.

Returns
‪bool

Definition at line 547 of file FormRuntime.php.

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

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

Member Data Documentation

◆ $configurationManager

ConfigurationManagerInterface TYPO3\CMS\Form\Domain\Runtime\FormRuntime::$configurationManager
protected

◆ $container

ContainerInterface TYPO3\CMS\Form\Domain\Runtime\FormRuntime::$container
protected

◆ $currentFinisher

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

Reference to the current running finisher

Definition at line 160 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 141 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 = null
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 130 of file FormRuntime.php.

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

◆ $formState

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

◆ $hashService

HashService TYPO3\CMS\Form\Domain\Runtime\FormRuntime::$hashService
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 148 of file FormRuntime.php.

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

◆ $objectManager

ObjectManagerInterface TYPO3\CMS\Form\Domain\Runtime\FormRuntime::$objectManager
protected

◆ $request

Request TYPO3\CMS\Form\Domain\Runtime\FormRuntime::$request = null
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 110 of file FormRuntime.php.