PickerConfig
in package
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
= []
$formName read-only
private
string
$formName
$labelResolver read-only
private
Closure|null
$labelResolver
= null
$minChars read-only
private
int
$minChars
= 2
$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
$targetField read-only
private
string
$targetField
$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
showgrid (:Admin:System:Page); null means suggester only, no modal - $fieldMap : array<string, string> = []
-
mapping of further form fields: data key (from the suggester
data/ gridsetPickerData()) -> 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 bylabelResolver. - $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([])andonClick -> redrawControl;BasePresenter::createFormsaves only through update/save, so this button does not save. null or a missing button means no re-render.picker.jsalways fires the DOM eventpicker: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
nullwhen creation failed. The closure lives in the presenter's picker trait, so the picker still knows neither the manager nor the entity, same assuggestCallback/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
addof the target presenter (:Admin:Eshop:ProductSetLink:add). Without it the picker would bypass privileges. Required as soon ascreateCallbackis set.
canCreate()
public
canCreate() : bool
Return values
boolcreate()
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}|nullgetCreatePrivilege()
public
getCreatePrivilege() : string|null
Return values
string|nullgetDisplayField()
public
getDisplayField() : string|null
Return values
string|nullgetFieldMap()
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
stringgetMinChars()
public
getMinChars() : int
Return values
intgetNestedContainer()
public
getNestedContainer() : string|null
Return values
string|nullgetSubmitButton()
public
getSubmitButton() : string|null
Return values
string|nullgetTargetContainer()
public
getTargetContainer() : string|null
Return values
string|nullgetTargetField()
public
getTargetField() : string
Return values
stringgetTargetParams()
public
getTargetParams() : array<string, mixed>
Return values
array<string, mixed>getTargetPresenter()
public
getTargetPresenter() : string|null
Return values
string|nullresolveLabel()
public
resolveLabel(int $id) : string|null
Parameters
- $id : int
Return values
string|nullsuggest()
public
suggest(string $query) : array<int, array{id: int, label: string, data?: array}>
Parameters
- $query : string