CoolCMS API

SearchBoxRegionTrait

Locality fields of the hero search box in Bazaar and Comcat.

Website with imported regions/districts/municipalities (RegionManager::hasSuggestableRegions()):

  • regionId is a hidden carrier of the selected node id (country, region, district or municipality),
  • regionText is the visible RegionSuggest field (the text is submitted even without a selection).

A website with countries only keeps the <select regionId> of tree roots. Either way regionId becomes the listing route segment (the router translates it to href) and then the lft/rgt subtree (RegionTrait::prepareRegionFilter()); the distance filter is not used.

The host (SearchBox) needs $regionManager (Front RegionManager), $regionSuggestFactory and, from FormTrait, the methods safeDefault() and pluckNames().

Table of Contents

Constants

REGION_FIELD_TEMPLATE  : string = __DIR__ . '/../../../Base/Front/Components/Sear...
Shared Latte part of the field; component (and theme) templates only place it.
REGION_LINK_NO_CATEGORY  : string = '-'
Placeholder category meaning "no category" in the listing link.
REGION_NOT_FOUND_MESSAGE  : string = 'front.system.components.regionSuggest.messages...
Flash shown when the typed locality cannot be resolved (full key; the layout translates it via `{_$flash->message}`).
REGION_PLACEHOLDER_KEY  : string = 'areaPlaceholder'
Suggest placeholder key (domain `front.system.components.regionSuggest`): region, district, municipality, postcode.

Methods

createComponentRegionSuggest()  : RegionSuggest
addRegionFields()  : void
Adds the locality fields to the form.
buildMainRegionOptions()  : array<int, NotTranslate>
buildRegionLinkParameters()  : array<string, mixed>
Adds `regionId` to the listing link parameters (and the placeholder category when there is none).
prepareRegionField()  : void
Sets variables for the shared Latte field part ({@see REGION_FIELD_TEMPLATE}).
resolveRegionLinkValue()  : int|string|null
Returns the `regionId` value for the listing link.
resolveSearchLanguageId()  : int
resolveSearchPreferRegionId()  : int|null
The country of the website localization takes precedence in the offer (same as in `RegionSuggest`).

Constants

REGION_FIELD_TEMPLATE

Shared Latte part of the field; component (and theme) templates only place it.

private string REGION_FIELD_TEMPLATE = __DIR__ . '/../../../Base/Front/Components/SearchBox/Templates/Default/Elements/Region.latte'

Placeholder category meaning "no category" in the listing link.

private string REGION_LINK_NO_CATEGORY = '-'

IMPORTANT: the route mask is <slug>[/<categoryId>][/<regionId>]; without a category the router would read /inzeraty/<region href> as a category and the listing would silently ignore the locality. The region menu (RegionListComponent) uses the same placeholder; the listing finds no such category, so no category filter applies.

REGION_NOT_FOUND_MESSAGE

Flash shown when the typed locality cannot be resolved (full key; the layout translates it via `{_$flash->message}`).

private string REGION_NOT_FOUND_MESSAGE = 'front.system.components.regionSuggest.messages.notFound'

REGION_PLACEHOLDER_KEY

Suggest placeholder key (domain `front.system.components.regionSuggest`): region, district, municipality, postcode.

private string REGION_PLACEHOLDER_KEY = 'areaPlaceholder'

Methods

addRegionFields()

Adds the locality fields to the form.

private addRegionFields(Form $form, callable $t) : void

The default comes from the URL, where regionId is translated to href in the route.

IMPORTANT: do not set it into the select without safeDefault(); a value outside the options throws a 500.

Parameters
$form : Form
$t : callable

buildMainRegionOptions()

private buildMainRegionOptions() : array<int, NotTranslate>
Return values
array<int, NotTranslate> —

tree roots (countries) for the <select> of a website without import

buildRegionLinkParameters()

Adds `regionId` to the listing link parameters (and the placeholder category when there is none).

private buildRegionLinkParameters(Form $form, ArrayHash $values, array<string, mixed> $params) : array<string, mixed>
Parameters
$form : Form
$values : ArrayHash
$params : array<string, mixed>
Return values
array<string, mixed>

prepareRegionField()

Sets variables for the shared Latte field part ({@see REGION_FIELD_TEMPLATE}).

private prepareRegionField() : void

resolveRegionLinkValue()

Returns the `regionId` value for the listing link.

private resolveRegionLinkValue(Form $form, ArrayHash $values) : int|string|null

Select: the chosen id; suggest: the id from the carrier or resolved from the text (RegionManager::resolveSearchRegionId()). A typed but unresolved locality yields the listing without a locality plus a warning, because silently ignoring it would look like results for the typed place.

Parameters
$form : Form
$values : ArrayHash
Return values
int|string|null

resolveSearchPreferRegionId()

The country of the website localization takes precedence in the offer (same as in `RegionSuggest`).

private resolveSearchPreferRegionId() : int|null
Return values
int|null
On this page

Search results