CoolCMS API

PickerConfig
in package

FinalYes

Configuration of one {@see Picker} instance. A pure value object created with a fluent or named-args notation in the picker trait (`UserPickerTrait::userPicker()` ...); not a DI service (config/common.neon excludes it from search, like the DataGrid configuration class).

The picker is shielded from any concrete manager: data is drawn through callbacks that the picker trait builds with its own manager (Admin and Front). The picker itself only renders the UI (text, suggester, button) and links it to the form's hidden field (formName + targetField).

Table of Contents

Properties

$createCallback  : Closure|null
$createPrivilege  : string|null
$displayField  : string|null
$fieldMap  : array<string|int, mixed>
$formName  : string
$labelResolver  : Closure|null
$minChars  : int
$nestedContainer  : string|null
$submitButton  : string|null
$suggestCallback  : Closure
$targetContainer  : string|null
$targetField  : string
$targetParams  : array<string|int, mixed>
$targetPresenter  : string|null

Methods

__construct()  : mixed
canCreate()  : bool
create()  : array{id: int, label: string}|null
Creates a record from the typed text. Returns null on failure (the picker reports it to the user).
getCreatePrivilege()  : string|null
getDisplayField()  : string|null
getFieldMap()  : array<string, string>
getFormName()  : string
getMinChars()  : int
getNestedContainer()  : string|null
getSubmitButton()  : string|null
getTargetContainer()  : string|null
getTargetField()  : string
getTargetParams()  : array<string, mixed>
getTargetPresenter()  : string|null
resolveLabel()  : string|null
suggest()  : array<int, array{id: int, label: string, data?: array}>

Properties

$createCallback read-only

private Closure|null $createCallback = null

$createPrivilege read-only

private string|null $createPrivilege = null

$displayField read-only

private string|null $displayField = null

$fieldMap read-only

private array<string|int, mixed> $fieldMap = []

$labelResolver read-only

private Closure|null $labelResolver = null

$nestedContainer read-only

private string|null $nestedContainer = null

$submitButton read-only

private string|null $submitButton = null

$suggestCallback read-only

private Closure $suggestCallback

$targetContainer read-only

private string|null $targetContainer = null

$targetParams read-only

private array<string|int, mixed> $targetParams = []

$targetPresenter read-only

private string|null $targetPresenter = null

Methods

__construct()

public __construct(callable(string): array<int, array{id: int, label: string, data?: array}> $suggestCallback, string $formName, string $targetField[, callable(int): Array|null $labelResolver = null ][, string|null $targetPresenter = null ][, array<string, string> $fieldMap = [] ][, array<string, mixed> $targetParams = [] ][, int $minChars = 2 ][, string|null $targetContainer = null ][, string|null $displayField = null ][, string|null $nestedContainer = null ][, string|null $submitButton = null ][, callable(string): Array|null $createCallback = null ][, string|null $createPrivilege = null ]) : mixed
Parameters
$suggestCallback : callable(string): array<int, array{id: int, label: string, data?: array}>

suggester text -> list of items (id + label + optional data for filling other fields)

$formName : string

name of the form whose hidden field the picker writes to (e.g. editForm)

$targetField : string

name of the hidden control in the form (e.g. parentId)

$labelResolver : callable(int): Array|null = null

id (from the hidden field on edit) -> label for the text input; null means no prefill

$targetPresenter : string|null = null

target presenter for the modal with the show grid (:Admin:System:Page); null means suggester only, no modal

$fieldMap : array<string, string> = []

mapping of further form fields: data key (from the suggester data / grid setPickerData()) -> name of the Nette control in the form. After selecting, JS fills these fields too (not just hidden + label). E.g. ['email' => 'ownerEmail', 'company' => 'ownerCompany'].

$targetParams : array<string, mixed> = []

further link parameters for the modal

$minChars : int = 2

minimum number of characters before the suggester starts

$targetContainer : string|null = null

name of the multiplier container in the form that holds the hidden field (addresses). null means the field is directly in the form (top-level). For a multiplier the picker addresses $form[$targetContainer][$index][$targetField].

$displayField : string|null = null

name of the text control (sibling of $targetField) for the label and suggester. Required in a multiplier so the label survives an AJAX re-render of the row. null means the picker renders a plain (not submitted) input filled by labelResolver.

$nestedContainer : string|null = null

name of the nested multiplier container (second level) when the picker sits in a multiplier inside a multiplier (groups -> parameters). The picker then addresses $form[$targetContainer][$i0][$nestedContainer][$i1][$targetField]. Requires a double index in the instance name (picker-<key>_<i0>_<i1>). null means a single level.

$submitButton : string|null = null

name of the form submit button that the picker "clicks" after a successful selection (naja -> AJAX re-render), so dependent fields are re-rendered (e.g. options of the selected parameter). The button should have validationScope([]) and onClick -> redrawControl; BasePresenter::createForm saves only through update/save, so this button does not save. null or a missing button means no re-render. picker.js always fires the DOM event picker:success (for custom wiring; preventDefault() suppresses the re-render).

$createCallback : callable(string): Array|null = null

Creating from the suggester: typed text -> newly created record, or null when creation failed. The closure lives in the presenter's picker trait, so the picker still knows neither the manager nor the entity, same as suggestCallback/labelResolver. null (default) means the picker cannot create and behaves as before. IMPORTANT: the closure must handle duplicates (an exact match returns the existing record instead of creating a second one); the picker does not know the code list content.

$createPrivilege : string|null = null

RBAC key that creating requires, typically add of the target presenter (:Admin:Eshop:ProductSetLink:add). Without it the picker would bypass privileges. Required as soon as createCallback is set.

canCreate()

public canCreate() : bool
Return values
bool

create()

Creates a record from the typed text. Returns null on failure (the picker reports it to the user).

public create(string $text) : array{id: int, label: string}|null
Parameters
$text : string
Return values
array{id: int, label: string}|null

getCreatePrivilege()

public getCreatePrivilege() : string|null
Return values
string|null

getDisplayField()

public getDisplayField() : string|null
Return values
string|null

getFieldMap()

public getFieldMap() : array<string, string>
Return values
array<string, string> —

data key to the control name in the form

getFormName()

public getFormName() : string
Return values
string

getMinChars()

public getMinChars() : int
Return values
int

getNestedContainer()

public getNestedContainer() : string|null
Return values
string|null

getSubmitButton()

public getSubmitButton() : string|null
Return values
string|null

getTargetContainer()

public getTargetContainer() : string|null
Return values
string|null

getTargetField()

public getTargetField() : string
Return values
string

getTargetParams()

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

getTargetPresenter()

public getTargetPresenter() : string|null
Return values
string|null

resolveLabel()

public resolveLabel(int $id) : string|null
Parameters
$id : int
Return values
string|null

suggest()

public suggest(string $query) : array<int, array{id: int, label: string, data?: array}>
Parameters
$query : string
Return values
array<int, array{id: int, label: string, data?: array}>
On this page

Search results