class FormStateService (View source)

Keeps submitted form data in the session so a failed request can refill the form.

This service handles storing and retrieving form data when validation errors occur, allowing form fields to retain their values after a failed submission.

Constants

private SESSION_KEY

private EXPIRY_TIME

Methods

__construct(SessionInterface $session)

No description

void
saveFormData(string $formId, array $data)

Save form data to the session with an expiry time

array|null
getFormData(string $formId)

Get form data from the session without removing it

void
clearFormData(string $formId)

Explicitly clear form data when it's no longer needed

string
generateFormId(string $prefix = '')

Generate a unique form ID based on the current request

void
rememberAddRecordForm(array $values)

Stash the zone editor's inline add-record form before processing, so a failed validation can re-display the submitted values.

void
rememberAddRecordError(array $error)

Record why the stashed add-record submission was refused.

array|null
addRecordFormWithError()

The stashed add-record values merged with their error, or null unless both are present. Non-destructive: the stash survives until the add succeeds or the zone changes.

void
forgetAddRecordForm()

Drop the stashed add-record form and its error, after a successful add.

void
trackAddRecordZone(int $zoneId)

Remember which zone the add-record stash belongs to, clearing it when the operator moves to a different zone so values never leak across zones.

Details

__construct(SessionInterface $session)

No description

Parameters

SessionInterface $session

void saveFormData(string $formId, array $data)

Save form data to the session with an expiry time

Parameters

string $formId

Unique identifier for the form

array $data

Form data to store

Return Value

void

array|null getFormData(string $formId)

Get form data from the session without removing it

Parameters

string $formId

Unique identifier for the form

Return Value

array|null

The form data or null if it doesn't exist or has expired

void clearFormData(string $formId)

Explicitly clear form data when it's no longer needed

Parameters

string $formId

Unique identifier for the form

Return Value

void

string generateFormId(string $prefix = '')

Generate a unique form ID based on the current request

Parameters

string $prefix

Optional prefix for the form ID

Return Value

string

The generated form ID

void rememberAddRecordForm(array $values)

Stash the zone editor's inline add-record form before processing, so a failed validation can re-display the submitted values.

These use the same session keys the zone editor always used, so the behaviour (and any in-flight sessions) are unchanged.

Parameters

array $values

The submitted add-record fields

Return Value

void

void rememberAddRecordError(array $error)

Record why the stashed add-record submission was refused.

Parameters

array $error

Error flags/message/field for the re-rendered form

Return Value

void

array|null addRecordFormWithError()

The stashed add-record values merged with their error, or null unless both are present. Non-destructive: the stash survives until the add succeeds or the zone changes.

Return Value

array|null

void forgetAddRecordForm()

Drop the stashed add-record form and its error, after a successful add.

Return Value

void

void trackAddRecordZone(int $zoneId)

Remember which zone the add-record stash belongs to, clearing it when the operator moves to a different zone so values never leak across zones.

Parameters

int $zoneId

Return Value

void