CoolCMS API

FormTrait

Table of Contents

Constants

LIST_PAGE_SLUG  : mixed = \App\Core\Routers\PageId::ESHOP_PRODUCT_LIST
Fixed id of the catalog page, the search target.

Methods

onSuccess()  : void
createComponentForm()  : Form
buildCategorySelectItems()  : array<int, NotTranslate>
Returns options of the root category select (`parent_id IS NULL`) for the template10 theme.
prepareParametersForRedirectLink()  : array<string, int|string>
Builds the parameters of the link to the catalog list.

Constants

LIST_PAGE_SLUG

Fixed id of the catalog page, the search target.

private mixed LIST_PAGE_SLUG = \App\Core\Routers\PageId::ESHOP_PRODUCT_LIST

Methods

onSuccess()

public onSuccess(Form $form, ArrayHash $values) : void
Parameters
$form : Form
$values : ArrayHash

buildCategorySelectItems()

Returns options of the root category select (`parent_id IS NULL`) for the template10 theme.

private buildCategorySelectItems() : array<int, NotTranslate>

It uses the same manager as ProductCategoryListComponent/Traits/InitializationTrait, with include(['translations']) and no asset, which the select does not need.

IMPORTANT: names are already localized DB data, not translation keys, so they are wrapped in NotTranslate. The form has a translator for labels and the select would otherwise look up every option as a key, and Tracy would report missing translations for category names.

Return values
array<int, NotTranslate>

Builds the parameters of the link to the catalog list.

private prepareParametersForRedirectLink(ArrayHash $values) : array<string, int|string>

The route 200 mask is <slug>[/<category>][/s-<search>][/p-<page=1>o-<order=0>].

IMPORTANT: page and order are always sent, even when they are defaults. Nette builds the URL even without an optional segment and without them fails with "Invalid link: Missing parameter".

IMPORTANT: order = 0 is the sentinel "the user did not choose a sort order" and must stay 0; otherwise the search would land on a list with manual sorting and Elasticsearch relevance would never be enabled.

The category is passed only when the user chose it in the select. The field always exists in the form but only the template10 theme renders it, so on other themes category stays empty. The router translates the id to a slug itself (as {plink} does in the category list).

Parameters
$values : ArrayHash
Return values
array<string, int|string>
On this page

Search results