CoolCMS API

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 selected 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>
Composes the link parameters for the list.
priceOptions()  : array<int|string, NotTranslate>
Returns "Price up to" options in the site currency (currency of the localization region): steps from `advert.bazaarPriceSteps` ({@see AdvertPriceStepsConfig}), caption by localization.
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

currentTypeOptionId()

Currently selected type option from the URL (`?p[<id>]=<optionId>`).

private currentTypeOptionId() : int|null
Return values
int|null

findTypeParameter()

private findTypeParameter() : object|null
Return values
object|null

languageId()

Id of the current language for reading entity translations.

private languageId() : int|null
Return values
int|null

loadMainCategories()

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 via getTranslation($languageId)?->getName() (see CategoryListComponent/Templates/Default/Style_1.latte). Without a language or translation the item is skipped so the select has no empty rows.

IMPORTANT: names are already localized data, not keys, so they are wrapped in NotTranslate. The form has a translator (for captions) and would otherwise look up every option as a key: the main page reported 32 missing translations.

Parameters
$items : iterable<string|int, object>
Return values
array<int, NotTranslate>

Composes the link parameters for the list.

private prepareParametersForRedirectLink(Form $form, ArrayHash $values) : array<string, mixed>

Route mask (cms_system_routes): <slug>[/<categoryId>][/<regionId>][/s-<search>][/p-<page>][/o-<order>]... What is not in the mask (p, priceTo) Nette appends as a query string.

Parameters
$form : Form
$values : ArrayHash
Return values
array<string, mixed>

priceOptions()

Returns "Price up to" options in the site currency (currency of the localization region): steps from `advert.bazaarPriceSteps` ({@see AdvertPriceStepsConfig}), caption by localization.

private priceOptions() : array<int|string, NotTranslate>

The option value is a bare number: the price filter is not converted.

Return values
array<int|string, NotTranslate> —

formatted amount, not a key, see self::pluckNames()

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, giving a 500 for the whole page, also in the header (StyleInline), i.e. 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>
Return values
int|string|null
On this page

Search results