DefaultsTrait
Table of Contents
Methods
- applyDefaults() : void
- Prefills the form from a map of values supplied by the child component (e.g. from the `Advert` entity via ParameterRels).
- isFieldSubmitted() : bool
- Returns whether the parameter field is present in the submitted POST.
Methods
applyDefaults()
Prefills the form from a map of values supplied by the child component (e.g. from the `Advert` entity via ParameterRels).
private
applyDefaults(Form $form, array<int, mixed> $entityValues[, array<string, mixed>|null $skipSubmittedPost = null ]) : void
With $skipSubmittedPost === null it is a classic GET prefill (setDefaultValue()). With an
array it is force mode: setValue() fills only fields whose key is not in this POST, i.e. fields
newly revealed by an AJAX category refresh on a submitted form, where setDefaultValue() is a
no-op. Fields that are in the POST (the value the user is typing) are skipped so the database
value does not overwrite them.
Parameters
- $form : Form
- $entityValues : array<int, mixed>
-
parameterId => value | value[] - $skipSubmittedPost : array<string, mixed>|null = null
-
raw POST (form control keys) or null
isFieldSubmitted()
Returns whether the parameter field is present in the submitted POST.
private
isFieldSubmitted(array<string, mixed> $rawPost, string $key) : bool
It also considers handler sub-keys (range: {key}_from/{key}_to). An empty but submitted
text input (key='') counts as present, which respects a deliberate clearing by the user.
New fields (a new category) are not in the POST at all, so it returns false and they are
filled from the database.
Parameters
- $rawPost : array<string, mixed>
- $key : string