FormTrait
Table of Contents
Constants
- TYPE_PARAMETER_KEY : mixed = 'type'
- Key of the parameter that carries the advert type. Options are its children in the tree.
Properties
- $typeParameterCache : object|null
Methods
- onSuccess() : void
- createComponentForm() : Form
- currentTypeOptionId() : int|null
- Currently chosen type option from the URL (`?p[<id>]=<optionId>`).
- findTypeParameter() : object|null
- languageId() : int|null
- Id of the current language for reading entity translations.
- loadMainCategories() : array<int, NotTranslate>
- loadTypeOptions() : array<int, NotTranslate>
- pluckNames() : array<int, NotTranslate>
- Extracts `id => name` from entities with translations.
- prepareParametersForRedirectLink() : array<string, mixed>
- Composition of the list link parameters.
- safeDefault() : int|string|null
- Preselected select value, only if it is really in its options.
Constants
TYPE_PARAMETER_KEY
Key of the parameter that carries the advert type. Options are its children in the tree.
private
mixed
TYPE_PARAMETER_KEY
= 'type'
Properties
$typeParameterCache
private
object|null
$typeParameterCache
= null
Methods
onSuccess()
public
onSuccess(Form $form, ArrayHash $values) : void
Parameters
- $form : Form
- $values : ArrayHash
createComponentForm()
protected
createComponentForm() : Form
Return values
FormcurrentTypeOptionId()
Currently chosen type option from the URL (`?p[<id>]=<optionId>`).
private
currentTypeOptionId() : int|null
Return values
int|nullfindTypeParameter()
private
findTypeParameter() : object|null
Return values
object|nulllanguageId()
Id of the current language for reading entity translations.
private
languageId() : int|null
Return values
int|nullloadMainCategories()
private
loadMainCategories() : array<int, NotTranslate>
Return values
array<int, NotTranslate>loadTypeOptions()
private
loadTypeOptions() : array<int, NotTranslate>
Return values
array<int, NotTranslate> —option id => name
pluckNames()
Extracts `id => name` from entities with translations.
private
pluckNames(iterable<string|int, object> $items) : array<int, NotTranslate>
NOTE: entities have no getName(): the name lives in the translation table and is read
through getTranslation($languageId)?->getName() (see
CategoryListComponent/Templates/Default/Style_1.latte). Without a language or without a
translation the item is skipped so that the select has no empty rows.
IMPORTANT: the names are already localized data, not keys, so they are wrapped in
NotTranslate. The form has a translator (for labels) and it would otherwise look up
every option as a key: the home page reported 32 missing translations.
Parameters
- $items : iterable<string|int, object>
Return values
array<int, NotTranslate>prepareParametersForRedirectLink()
Composition of the list link parameters.
private
prepareParametersForRedirectLink(Form $form, ArrayHash $values) : array<string, mixed>
Route mask (cms_system_routes):
p) Nette appends as a query string.
Parameters
- $form : Form
- $values : ArrayHash
Return values
array<string, mixed>safeDefault()
Preselected select value, only if it is really in its options.
private
safeDefault(mixed $value, array<int|string, string|Stringable> $options) : int|string|null
IMPORTANT: without this guard the advert list crashes. The router translates
categoryId and regionId in the URL to a name (CategoryNameTranslator), so
getParameter('categoryId') returns 'automobily', not 12. Nette
SelectBox::setDefaultValue() throws InvalidArgumentException for a value outside the
options, so the whole page returns 500, also in the header (StyleInline), that is on
/inzerce and all lists.
An unknown value is therefore ignored and the select stays on the prompt.
Parameters
- $value : mixed
- $options : array<int|string, string|Stringable>