PickerHostTrait
Host trait for {@see Picker} components in a presenter.
Unifies createComponentPicker (multicontrol: one picker instance per field). The presenter
only uses this trait plus the concrete picker traits (PagePickerTrait,
NewsletterAddressPickerTrait, ...), returns the configurations from pickers() and
renders {control picker-<key>} in Latte ({control "picker-<key>_<index>"} for a
multiplier row; the index is separated by an underscore, see parsePickerName()).
The host must provide:
$this->pickerFactory(PickerFactory, typically constructor-injected),- an implementation of pickers().
Table of Contents
Methods
- createComponentPicker() : Multiplier<string|int, Picker>
- pickers() : array<string, PickerConfig>
- Returns the picker configurations of the presenter, keyed by logical name (`parentId`, `address`, ...). Must be pure and idempotent: it is also called on the AJAX signal `suggest!`, when the form may not be built yet.
-
parsePickerName()
: array{0: string, 1: list
} - Splits a picker instance name into the config key plus row indexes (multiplier and nested multiplier). `parentId` -> `['parentId', []]`; `address_2` -> `['address', ['2']]`; `parameter_1_0` -> `['parameter', ['1','0']]` (nested).
Methods
createComponentPicker()
protected
createComponentPicker() : Multiplier<string|int, Picker>
Return values
Multiplier<string|int, Picker>pickers()
Returns the picker configurations of the presenter, keyed by logical name (`parentId`, `address`, ...). Must be pure and idempotent: it is also called on the AJAX signal `suggest!`, when the form may not be built yet.
protected
abstract pickers() : array<string, PickerConfig>
Return values
array<string, PickerConfig>parsePickerName()
Splits a picker instance name into the config key plus row indexes (multiplier and nested multiplier). `parentId` -> `['parentId', []]`; `address_2` -> `['address', ['2']]`; `parameter_1_0` -> `['parameter', ['1','0']]` (nested).
private
parsePickerName(string $name) : array{0: string, 1: list}
The separator is an underscore, not a dash: - is the component path separator in Nette
({control picker-address_0} = Multiplier picker -> child address_0).
A config key must not end with _<number> (keys: parentId, address, parameter).
Parameters
- $name : string