SearchBox
extends BaseComponent
in package
uses
FormTrait, SearchBoxRegionTrait
Search box of the Comcat module.
Styles: Mini - full-text + button (module headers) Medium - full-text + category + region (hero /inzerce, /firmy) Large - type switch + category/region/price (template2 home page)
Style and StyleInline are backward-compatible aliases for Mini: template1, the
active theme, calls them. Do not remove them without changing its templates.
Usage:
{control frontComcatSearchBox, 'Mini'}
{control frontComcatSearchBox:medium}
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.
- TYPE_PARAMETER_KEY : mixed = 'type'
- Key of the parameter that carries the advert type. Options are its children in the tree.
Properties
- $container : Container
- $routerDispatcher : RouterDispatcher
- $translator : ITranslator
- $appContext : AppContext
- $componentParameters : array<string, mixed>
- $currencyContext : CurrencyContext|null
- $deviceDetector : DeviceDetector|null
- $languageContext : LanguageContext|null
- $localizationContext : LocalizationContext|null
- $settingContext : SettingContext
- $themeContext : ThemeContext|null
- $translatorDomain : string|null
- $categoryManager : CategoryManager
- $parameterManager : ParameterManager
- $regionManager : RegionManager
- $regionSuggestFactory : RegionSuggestFactory
- $typeParameterCache : object|null
Methods
- __call() : mixed
- Dispatches `renderXyz()` to `render('Xyz', ...$args)`.
- __construct() : mixed
- createComponent() : IComponent|null
- getAppContext() : AppContext
- getComponentParameter() : mixed
- Returns a component parameter, or null when it is not set.
- getContainer() : Container
- getCurrencyContext() : CurrencyContext|null
- getLanguageContext() : LanguageContext|null
- getLocalizationContext() : LocalizationContext|null
- getRouterDispatcher() : RouterDispatcher
- getSettingContext() : SettingContext
- getSettings() : array<int, array<string, mixed>>
- getThemeContext() : ThemeContext|null
- hasServiceByType() : bool
- Returns whether the container has a service of the given type.
- initializeAllContexts() : void
- injectDeviceDetector() : void
- onCreate() : void
- onSuccess() : void
- render() : void
- renderLarge() : void
- Type switch + category/region/price. Template2 home page.
- renderMedium() : void
- Full-text + category + region. Hero signposts (/inzerce, /firmy).
- renderMini() : void
- Full-text + button. Module headers.
- 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.
- createComponentForm() : Form
- createComponentRegionSuggest() : RegionSuggest
- frontPresenter() : BasePresenter|null
- Returns the front presenter the component is attached to (null outside the front end or when detached).
- getTranslator() : ITranslator
- setTemplateFile() : void
- setTranslator() : self
- addRegionFields() : void
- Adds the locality fields to the form.
- applyStyleRules() : void
- Full-text is required only in `mini`, where it is the only field.
- buildMainRegionOptions() : array<int, NotTranslate>
- buildRegionLinkParameters() : array<string, mixed>
- Adds `regionId` to the listing link parameters (and the placeholder category when there is none).
- 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).
- 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.
- 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`).
- safeDefault() : int|string|null
- Preselected select value, only if it is really in its options.
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'
REGION_LINK_NO_CATEGORY
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'
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
$container
public
Container
$container
Attributes
- #[Inject]
$routerDispatcher
public
RouterDispatcher
$routerDispatcher
$translator
public
ITranslator
$translator
Tags
$appContext
protected
AppContext
$appContext
$componentParameters
protected
array<string, mixed>
$componentParameters
= []
component parameters set by setComponentParameter()
$currencyContext
protected
CurrencyContext|null
$currencyContext
= NULL
$deviceDetector
protected
DeviceDetector|null
$deviceDetector
= NULL
$languageContext
protected
LanguageContext|null
$languageContext
= NULL
$localizationContext
protected
LocalizationContext|null
$localizationContext
= NULL
$settingContext
protected
SettingContext
$settingContext
$themeContext
protected
ThemeContext|null
$themeContext
= NULL
$translatorDomain
protected
string|null
$translatorDomain
= 'front.comcat.components.searchBox'
$categoryManager read-only
private
CategoryManager
$categoryManager
$parameterManager read-only
private
ParameterManager
$parameterManager
$regionManager read-only
private
RegionManager
$regionManager
$regionSuggestFactory read-only
private
RegionSuggestFactory
$regionSuggestFactory
$typeParameterCache
private
object|null
$typeParameterCache
= null
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(CategoryManager $categoryManager, RegionManager $regionManager, ParameterManager $parameterManager, RegionSuggestFactory $regionSuggestFactory) : mixed
Parameters
- $categoryManager : CategoryManager
- $regionManager : RegionManager
- $parameterManager : ParameterManager
- $regionSuggestFactory : RegionSuggestFactory
createComponent()
public
createComponent(string $name) : IComponent|null
Parameters
- $name : string
Return values
IComponent|nullgetAppContext()
public
getAppContext() : AppContext
Return values
AppContextgetComponentParameter()
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
ContainergetCurrencyContext()
public
getCurrencyContext() : CurrencyContext|null
Return values
CurrencyContext|nullgetLanguageContext()
public
getLanguageContext() : LanguageContext|null
Return values
LanguageContext|nullgetLocalizationContext()
public
getLocalizationContext() : LocalizationContext|null
Return values
LocalizationContext|nullgetRouterDispatcher()
public
getRouterDispatcher() : RouterDispatcher
Return values
RouterDispatchergetSettingContext()
public
getSettingContext() : SettingContext
Return values
SettingContextgetSettings()
public
getSettings() : array<int, array<string, mixed>>
Return values
array<int, array<string, mixed>>getThemeContext()
public
getThemeContext() : ThemeContext|null
Return values
ThemeContext|nullhasServiceByType()
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
Return values
boolinitializeAllContexts()
public
initializeAllContexts() : void
injectDeviceDetector()
public
injectDeviceDetector(DeviceDetector $detector) : void
Parameters
- $detector : DeviceDetector
onCreate()
public
onCreate() : void
onSuccess()
public
onSuccess(Form $form, ArrayHash $values) : void
Parameters
- $form : Form
- $values : ArrayHash
render()
public
render([string $style = 'Style' ]) : void
Parameters
- $style : string = 'Style'
renderLarge()
Type switch + category/region/price. Template2 home page.
public
renderLarge() : void
renderMedium()
Full-text + category + region. Hero signposts (/inzerce, /firmy).
public
renderMedium() : void
renderMini()
Full-text + button. Module headers.
public
renderMini() : void
setAppContext()
public
setAppContext(AppContext $appContext) : $this
Parameters
- $appContext : AppContext
Return values
$thissetComponentParameter()
Sets a component parameter.
public
setComponentParameter(string $name, mixed $value) : void
Parameters
- $name : string
- $value : mixed
setCurrencyContext()
public
setCurrencyContext(CurrencyContext|null $currencyContext) : $this
Parameters
- $currencyContext : CurrencyContext|null
Return values
$thissetLanguageContext()
public
setLanguageContext(LanguageContext|null $languageContext) : $this
Parameters
- $languageContext : LanguageContext|null
Return values
$thissetLocalizationContext()
public
setLocalizationContext(LocalizationContext|null $localizationContext) : $this
Parameters
- $localizationContext : LocalizationContext|null
Return values
$thissetSettingContext()
public
setSettingContext(SettingContext $settingContext) : $this
Parameters
- $settingContext : SettingContext
Return values
$thissetThemeContext()
public
setThemeContext(ThemeContext|null $themeContext) : $this
Parameters
- $themeContext : ThemeContext|null
Return values
$thissetup()
public
setup(BasePresenter|BasePresenter $presenter) : void
Parameters
- $presenter : BasePresenter|BasePresenter
setupAppContext()
public
setupAppContext(AppContext $appContext) : void
Parameters
- $appContext : AppContext
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
Return values
TcreateComponentForm()
protected
createComponentForm() : Form
Return values
FormcreateComponentRegionSuggest()
protected
createComponentRegionSuggest() : RegionSuggest
Return values
RegionSuggestfrontPresenter()
Returns the front presenter the component is attached to (null outside the front end or when detached).
protected
frontPresenter() : BasePresenter|null
Return values
BasePresenter|nullgetTranslator()
protected
getTranslator() : ITranslator
Return values
ITranslatorsetTemplateFile()
protected
setTemplateFile(string $dir, string $filename) : void
Parameters
- $dir : string
- $filename : string
setTranslator()
protected
setTranslator(ITranslator $translator) : self
Parameters
- $translator : ITranslator
Return values
selfaddRegionFields()
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
applyStyleRules()
Full-text is required only in `mini`, where it is the only field.
private
applyStyleRules(string $style) : void
In medium there are category and region next to it: the user may want to browse a
whole category and type nothing, so a requirement would block that. large has no
full-text at all.
Parameters
- $style : string
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>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|nullcreateStandardComponent()
Creates a standard component (not a multiplier).
private
createStandardComponent(string $name) : IComponent|null
Parameters
- $name : string
Return values
IComponent|nullcurrentTypeOptionId()
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>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|nullresolveSearchLanguageId()
private
resolveSearchLanguageId() : int
Return values
intresolveSearchPreferRegionId()
The country of the website localization takes precedence in the offer (same as in `RegionSuggest`).
private
resolveSearchPreferRegionId() : int|null
Return values
int|nullsafeDefault()
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>