CoolCMS API

AdvertFilterBox extends ParameterForm
in package
uses LoadingTrait, RegionSuggestHostTrait

Abstract component for a modular form built from parameters.

A child component supplies:

  • loadParameters() and loadParameterGroups(): data from its own managers
  • buildContext(): fills items for special selects (currency, region, comcat)
  • getMode(): form or search (form by default)
  • processSubmit(): saving or submitting the values (runs before the $onSuccess callbacks)
  • optionally getEntityValues(): prefill from an entity
  • optionally beforeSubmitButton(): custom fields before the submit button
  • optionally buildRegistry(): custom handlers

Table of Contents

Constants

REGION_PREVIEW_KEYS  : array<string|int, mixed> = ['city', 'zip', 'country']
Parameters that the preview prefills after a selection (parameter key = item data key).

Properties

$categoryId  : int|null
$container  : Container
$onError  : array<string|int, callable(Form, static): void>
Signature: function(Form $form, self $component): void
$onSuccess  : array<string|int, callable(Form, ArrayHash, static): void>
$onValidate  : array<string|int, callable(Form, ArrayHash, static): void>
Events for the consumer (presenter / parent control). `ParameterForm` only renders and validates; business logic (save, email, redirect) belongs to whoever instantiates the component.
$routerDispatcher  : RouterDispatcher
$translator  : ITranslator
$appContext  : AppContext
$componentParameters  : array<string, mixed>
$context  : ParameterFormContext
$currencyContext  : CurrencyContext|null
$deviceDetector  : DeviceDetector|null
$itemsByGroups  : array<int, array<int, ParameterFormItem>>
$languageContext  : LanguageContext|null
$localizationContext  : LocalizationContext|null
$parameterAndOptionList  : array<int, ParameterInterface>
$parameterGroupList  : array<int, ParameterGroupInterface>
$parameterItems  : array<int, ParameterFormItem>
$registry  : ParameterHandlerRegistry
$settingContext  : SettingContext
$themeContext  : ThemeContext|null
$translatorDomain  : string|null
Translation domain is set by the module subclass (`AdvertForm`, `AdvertFilterBox`, ...).
$categoryManager  : CategoryManager
$categoryParameterRelManager  : CategoryParameterRelManager
$fieldBuilder  : ParameterFieldBuilder|null
$parameterGroupManager  : ParameterGroupManager
$parameterManager  : ParameterManager
$parametersInitialized  : bool
$regionManager  : RegionManager
$regionSuggestFactory  : RegionSuggestFactory

Methods

__call()  : mixed
Dispatches `renderXyz()` to `render('Xyz', ...$args)`.
__construct()  : mixed
createComponent()  : IComponent|null
getActiveFilters()  : array<int, array{parameterId: int, parameter: string, label: string, remove: array|null}>
Returns active filters for the badges above the list (`.pactive`), one entry per cancelable value, so "Sony" and "Canon" are two badges, not one.
getAppContext()  : AppContext
getComponentParameter()  : mixed
Returns a component parameter, or null when it is not set.
getContainer()  : Container
getCurrencyContext()  : CurrencyContext|null
getGroupChosenCount()  : int
Returns how many options of a group are selected, shown as a badge on the collapsible heading (`.filter-box__chosen`) so a collapsed group still shows that it filters.
getLanguageContext()  : LanguageContext|null
getLocalizationContext()  : LocalizationContext|null
getRouterDispatcher()  : RouterDispatcher
getSettingContext()  : SettingContext
getSettings()  : array<int, array<string, mixed>>
getThemeContext()  : ThemeContext|null
getUploaderControlMap()  : array<string, string>
Map of form control name to uploader child name. Latte looks it up while iterating `$group->getControls()`; when an entry exists for an input, it renders the dropzone plus the classic input with a toggle.
getUploaderParameterIds()  : array<string|int, int>
Ids of parameters that have a dropzone uploader. A child may override it for different behavior (for example no uploaders: an empty array).
hasServiceByType()  : bool
Returns whether the container has a service of the given type.
initializeAllContexts()  : void
injectDeviceDetector()  : void
onCreate()  : void
render()  : void
renderActiveFilters()  : void
Renders badges of active filters above the list, not inside the filter: otherwise canceling a filter would be reachable only by scrolling back up.
renderJs()  : void
setAppContext()  : $this
setComponentParameter()  : void
Sets a component parameter.
setCurrencyContext()  : $this
setLanguageContext()  : $this
setLocalizationContext()  : $this
setSettingContext()  : $this
setThemeContext()  : $this
setup()  : void
setupAppContext()  : void
typedComponent()  : T
Returns a subcomponent with a verified type.
uploaderName()  : string
Name of the child uploader component for an upload parameter.
beforeRender()  : void
Hook: a child component may add its own template variables (for example the edited entity).
beforeSubmitButton()  : void
Hook: a child component may add its own fields before submit (recaptcha, password input, agreement checkbox and similar).
buildContext()  : void
buildRegistry()  : ParameterHandlerRegistry
Default registry covering all `ParameterType` constants. A child component may override it to add its own handlers (for example module-specific types).
createComponentForm()  : Form
createComponentRegionSuggest()  : Multiplier<string|int, RegionSuggest>
extractParameterValues()  : array<int, array<int, array{value: mixed, value2?: ?string}>>
Helper that extracts form values. Returns only persistable parameters, i.e. not file/image types.
findParameterByKey()  : ParameterInterface|null
frontPresenter()  : BasePresenter|null
Returns the front presenter the component is attached to (null outside the front end or when detached).
getCurrentCategory()  : Category|null
getEntityValues()  : array<int, mixed>
Hook: map of entity values for prefill (parameterId => value | value[]).
getFieldBuilder()  : ParameterFieldBuilder
Lazy shared builder of parameter fields, initialized from the resolved engine state (items/groups/context/mode). Entity values are read at the first build (after `setAdvert()`/`setCategoryList()`), as with {@see \App\Core\Form\Parameters\Building\DefaultsTrait::applyDefaults()}.
getMode()  : string
Hook: mode that selects `getType` or `getSearchType` on a parameter.
getParameterTranslation()  : ParameterTextInterface|null
getSubmitLabel()  : string
getTranslator()  : ITranslator
hasResolvedType()  : bool
For a child component: tells whether the form contains a parameter of the given type (respecting the mode via `resolveType()`).
initParameters()  : void
isUploadParameter()  : bool
A classic `IMAGE` / `FILE` parameter has its own `<input type="file">` (via the handler); the dropzone uploader handles only the multi-upload `*_UPLOADER` variants.
loadParameterGroups()  : array<string|int, mixed>
loadParameters()  : array<string|int, ParameterFormItem>
parameterKey()  : string
Form control key of a parameter (`parameter_<id>`). Field building is done by the shared {@see \App\Core\Form\Parameters\ParameterFieldBuilder}, but the engine and its consumers (filter URL params, email/region denormalization) need the same key to look up submitted values.
processSubmit()  : void
resolveDefaultValue()  : string|null
resolveType()  : int|null
setTemplateFile()  : void
setTranslator()  : self
usesDefaultParameters()  : bool
Hook: when a child component returns true, only parameters with `getDefault()` = true (classic) or `getSearchDefault()` = true (search) are shown.
addFulltextField()  : void
Fulltext field `search` above the whole filter.
aggregateCategoryParameterRels()  : array<int, array{order: int, groupId: ?int}>
The filter has a single category (from the presenter), but the interface stays similar to `AdvertForm::aggregateCategoryParameterRels()`; if the filter ever handles several categories (multi-category list), the aggregation rules are already here: - useInSearch: a parameter is skipped when all rels have it false - order: min, groupId: first wins
applyUrlDefaults()  : void
buildParameterAndOptionList()  : void
Returns ids of the parameters that this parameterId uses (directly or through options), for lookup from rules. Options have no per-category override, so they are read straight from the Parameter entity.
buildRegionPreviewFieldMap()  : array<string, string>
createMultiplierComponent()  : Multiplier<string|int, IComponent>
Creates a multiplier for the component.
createNewComponentInstance()  : IComponent|null
Creates a new component instance without adding it to the presenter; used by the multiplier.
createStandardComponent()  : IComponent|null
Creates a standard component (not a multiplier).
indexById()  : array<int, T>
indexItemsByGroups()  : void
indexItemsById()  : array<int, ParameterFormItem>
initRegionPickerContext()  : void
Selection validator for {@see ParameterFormContext::$regionValidator}: the advert form accepts only an active municipality (tree leaf), so an old advert filed under a country forces choosing a municipality on edit.

Constants

REGION_PREVIEW_KEYS

Parameters that the preview prefills after a selection (parameter key = item data key).

private array<string|int, mixed> REGION_PREVIEW_KEYS = ['city', 'zip', 'country']

Properties

$categoryId

public int|null $categoryId = null
Attributes
#[Persistent]

$onError

Signature: function(Form $form, self $component): void

public array<string|int, callable(Form, static): void> $onError = []

$onSuccess

public array<string|int, callable(Form, ArrayHash, static): void> $onSuccess = []

$onValidate

Events for the consumer (presenter / parent control). `ParameterForm` only renders and validates; business logic (save, email, redirect) belongs to whoever instantiates the component.

public array<string|int, callable(Form, ArrayHash, static): void> $onValidate = []

Signature: function(Form $form, ArrayHash $values, self $component): void

$componentParameters

protected array<string, mixed> $componentParameters = []

component parameters set by setComponentParameter()

$parameterAndOptionList

protected array<int, ParameterInterface> $parameterAndOptionList = []

parameters together with their options (for lookup from rules)

$parameterItems

protected array<int, ParameterFormItem> $parameterItems = []

indexed by parameterId, with values resolved per form (order/required/groupId)

$translatorDomain

Translation domain is set by the module subclass (`AdvertForm`, `AdvertFilterBox`, ...).

protected string|null $translatorDomain = 'front.bazaar.components.advertFilterBox'

$parametersInitialized

private bool $parametersInitialized = false

Methods

__call()

Dispatches `renderXyz()` to `render('Xyz', ...$args)`.

public __call(string $name, array<string|int, mixed> $args) : mixed

Called only when the component has no renderXyz() method of its own.

Parameters
$name : string
$args : array<string|int, mixed>

__construct()

public __construct(ParameterManager $parameterManager, ParameterGroupManager $parameterGroupManager, CategoryParameterRelManager $categoryParameterRelManager, CategoryManager $categoryManager, RegionManager $regionManager, RegionSuggestFactory $regionSuggestFactory) : mixed
Parameters
$parameterManager : ParameterManager
$parameterGroupManager : ParameterGroupManager
$categoryParameterRelManager : CategoryParameterRelManager
$categoryManager : CategoryManager
$regionManager : RegionManager
$regionSuggestFactory : RegionSuggestFactory

createComponent()

public createComponent(string $name) : IComponent|null
Parameters
$name : string
Return values
IComponent|null

getActiveFilters()

Returns active filters for the badges above the list (`.pactive`), one entry per cancelable value, so "Sony" and "Canon" are two badges, not one.

public getActiveFilters() : array<int, array{parameterId: int, parameter: string, label: string, remove: array|null}>

Read from request parameters (p[<parameterId>]) and from already loaded parameter entities (optionsCollection is in the filter includes), so it costs no extra query.

remove is the p value without that one option; the template turns it into a link via {plink}. When nothing remains after removal it is null and the link leads to the list without a filter.

Return values
array<int, array{parameterId: int, parameter: string, label: string, remove: array|null}>

getComponentParameter()

Returns a component parameter, or null when it is not set.

public getComponentParameter(string $name) : mixed
Parameters
$name : string

getContainer()

public getContainer() : Container
Return values
Container

getGroupChosenCount()

Returns how many options of a group are selected, shown as a badge on the collapsible heading (`.filter-box__chosen`) so a collapsed group still shows that it filters.

public getGroupChosenCount(ControlGroup $group) : int

Counted from the form values, i.e. request parameters, so it costs no extra query. A multi-value field (CheckboxList/MultiSelect) counts per item, a single-value one as 1. Buttons and hidden fields are skipped: they are not user choices.

Lives on the shared base because Style_Filter.latte serves the e-shop, advert and company catalog filters, so every child gets it at once.

Parameters
$group : ControlGroup
Return values
int

getSettings()

public getSettings() : array<int, array<string, mixed>>
Return values
array<int, array<string, mixed>>

getUploaderControlMap()

Map of form control name to uploader child name. Latte looks it up while iterating `$group->getControls()`; when an entry exists for an input, it renders the dropzone plus the classic input with a toggle.

public getUploaderControlMap() : array<string, string>

Assumes the child creates a child component named uploaderName() for each uploader parameter (typically via a createComponent factory). Components without uploader children override getUploaderParameterIds() to return [].

Return values
array<string, string>

getUploaderParameterIds()

Ids of parameters that have a dropzone uploader. A child may override it for different behavior (for example no uploaders: an empty array).

public getUploaderParameterIds() : array<string|int, int>
Return values
array<string|int, int>

hasServiceByType()

Returns whether the container has a service of the given type.

public hasServiceByType(string $className) : bool

The name is composed dynamically (module plus component), so class_exists() runs first, and a true result guarantees a valid type.

Parameters
$className : string
Tags
phpstan-assert-if-true

class-string $className

Return values
bool

render()

public render([string $style = 'Style_1' ]) : void
Parameters
$style : string = 'Style_1'

renderActiveFilters()

Renders badges of active filters above the list, not inside the filter: otherwise canceling a filter would be reachable only by scrolling back up.

public renderActiveFilters() : void

Called from the list template as {control filterBox:activeFilters}. Renders nothing at all (not even an empty wrapper) when no filter is active.

setComponentParameter()

Sets a component parameter.

public setComponentParameter(string $name, mixed $value) : void
Parameters
$name : string
$value : mixed

typedComponent()

Returns a subcomponent with a verified type.

public typedComponent(string $name, T> $type) : T

Use it instead of an inline @var above $this['x'] (which does not narrow the type) and instead of the generic IComponent that $this['x'] returns. See Form::typedComponent().

Parameters
$name : string
$type : T>
Tags
template
Return values
T

uploaderName()

Name of the child uploader component for an upload parameter.

public uploaderName(ParameterInterface $parameter) : string

In Latte: {control "uploader_$parameterId"}.

Parameters
$parameter : ParameterInterface
Return values
string

beforeRender()

Hook: a child component may add its own template variables (for example the edited entity).

protected beforeRender(string $style) : void
Parameters
$style : string

beforeSubmitButton()

Hook: a child component may add its own fields before submit (recaptcha, password input, agreement checkbox and similar).

protected beforeSubmitButton(Form $form) : void
Parameters
$form : Form

extractParameterValues()

Helper that extracts form values. Returns only persistable parameters, i.e. not file/image types.

protected extractParameterValues(ArrayHash $values) : array<int, array<int, array{value: mixed, value2?: ?string}>>

The key is parameterId, the value a list of rows to persist; the handler decides (scalar: 1 row, multiselect: N rows, range: 1 row with value+value2).

Parameters
$values : ArrayHash
Return values
array<int, array<int, array{value: mixed, value2?: ?string}>>

frontPresenter()

Returns the front presenter the component is attached to (null outside the front end or when detached).

protected frontPresenter() : BasePresenter|null
Return values
BasePresenter|null

getEntityValues()

Hook: map of entity values for prefill (parameterId => value | value[]).

protected getEntityValues() : array<int, mixed>

Empty by default; a component without an entity (new record) has nothing to prefill.

Return values
array<int, mixed>

getFieldBuilder()

Lazy shared builder of parameter fields, initialized from the resolved engine state (items/groups/context/mode). Entity values are read at the first build (after `setAdvert()`/`setCategoryList()`), as with {@see \App\Core\Form\Parameters\Building\DefaultsTrait::applyDefaults()}.

protected getFieldBuilder() : ParameterFieldBuilder
Return values
ParameterFieldBuilder

getMode()

Hook: mode that selects `getType` or `getSearchType` on a parameter.

protected getMode() : string

Form by default (advert/insert); search forms return MODE_SEARCH.

Return values
string

getSubmitLabel()

protected getSubmitLabel() : string
Return values
string

getTranslator()

protected getTranslator() : ITranslator
Return values
ITranslator

hasResolvedType()

For a child component: tells whether the form contains a parameter of the given type (respecting the mode via `resolveType()`).

protected hasResolvedType(int $type) : bool
Parameters
$type : int
Return values
bool

initParameters()

protected initParameters() : void

isUploadParameter()

A classic `IMAGE` / `FILE` parameter has its own `<input type="file">` (via the handler); the dropzone uploader handles only the multi-upload `*_UPLOADER` variants.

protected isUploadParameter(ParameterInterface $parameter) : bool
Parameters
$parameter : ParameterInterface
Return values
bool

loadParameterGroups()

protected loadParameterGroups() : array<string|int, mixed>
Return values
array<string|int, mixed>

parameterKey()

Form control key of a parameter (`parameter_<id>`). Field building is done by the shared {@see \App\Core\Form\Parameters\ParameterFieldBuilder}, but the engine and its consumers (filter URL params, email/region denormalization) need the same key to look up submitted values.

protected parameterKey(ParameterInterface $parameter) : string
Parameters
$parameter : ParameterInterface
Return values
string

processSubmit()

protected processSubmit(Form $_form, ArrayHash $values) : void
Parameters
$_form : Form
$values : ArrayHash

setTemplateFile()

protected setTemplateFile(string $dir, string $filename) : void
Parameters
$dir : string
$filename : string

setTranslator()

protected setTranslator(ITranslator $translator) : self
Parameters
$translator : ITranslator
Return values
self

usesDefaultParameters()

Hook: when a child component returns true, only parameters with `getDefault()` = true (classic) or `getSearchDefault()` = true (search) are shown.

protected usesDefaultParameters() : bool
Return values
bool

addFulltextField()

Fulltext field `search` above the whole filter.

private addFulltextField(Form $form) : void

Parameter fields of the filter compare values exactly, so a text parameter ("Name") is useless as a filter: the user would have to hit the string character by character. The presenter already has a fulltext independent of parameters: ParameterTrait reads getParameter('search') and builds prepareAdvertSearchFilter() from it (an ES query with a transparent fallback to MySQL MATCH_AGAINST over parameterRels.value), the same path as the header search field (SearchBox).

So the value only has to reach the URL parameter search; no new filter logic exists. The field is named search because it must match the route mask ([/s-<search [^/]+>]), otherwise it would not reach the query.

NOTE: the element name search does not collide with the submit, which is named save (see FormTrait); the translation key search is its caption ("Filter"). This field's caption therefore has its own branch fulltext.*.

Style_Filter.latte renders the field above the parameter groups and skips it in the group listing so it does not appear twice.

Parameters
$form : Form

aggregateCategoryParameterRels()

The filter has a single category (from the presenter), but the interface stays similar to `AdvertForm::aggregateCategoryParameterRels()`; if the filter ever handles several categories (multi-category list), the aggregation rules are already here: - useInSearch: a parameter is skipped when all rels have it false - order: min, groupId: first wins

private aggregateCategoryParameterRels(Category $category) : array<int, array{order: int, groupId: ?int}>
Parameters
$category : Category
Return values
array<int, array{order: int, groupId: ?int}>

buildParameterAndOptionList()

Returns ids of the parameters that this parameterId uses (directly or through options), for lookup from rules. Options have no per-category override, so they are read straight from the Parameter entity.

private buildParameterAndOptionList() : void

buildRegionPreviewFieldMap()

private buildRegionPreviewFieldMap() : array<string, string>
Return values
array<string, string> —

data key => form control name of the parameter

createMultiplierComponent()

Creates a multiplier for the component.

private createMultiplierComponent(string $name) : Multiplier<string|int, IComponent>
Parameters
$name : string
Return values
Multiplier<string|int, IComponent>

createNewComponentInstance()

Creates a new component instance without adding it to the presenter; used by the multiplier.

private createNewComponentInstance(string $baseName[, int|string|null $uniqueKey = null ]) : IComponent|null
Parameters
$baseName : string
$uniqueKey : int|string|null = null
Return values
IComponent|null

createStandardComponent()

Creates a standard component (not a multiplier).

private createStandardComponent(string $name) : IComponent|null
Parameters
$name : string
Return values
IComponent|null

indexById()

private indexById(array<string|int, T> $items) : array<int, T>
Parameters
$items : array<string|int, T>
Tags
template
Return values
array<int, T>

indexItemsByGroups()

private indexItemsByGroups() : void

initRegionPickerContext()

Selection validator for {@see ParameterFormContext::$regionValidator}: the advert form accepts only an active municipality (tree leaf), so an old advert filed under a country forces choosing a municipality on edit.

private initRegionPickerContext() : void
On this page

Search results