UserPickerTrait
User picker: the canonical pattern for "many objects have a user" (advert owner, article author, ...).
The presenter uses the trait and calls userPicker() from pickers(); it can be used several
times on one page (two different fields) with a different targetField.
Demonstrates multi-field mapping: the label is "First Last" and fieldMap (data key email)
additionally fills the e-mail into a separate form field.
Uses the Admin UserManager (CRUD over the Api endpoint api/system/user via ApiBridge), the
same $userManager property as UserTrait of the admin
BasePresenter; the types match, so the properties do not collide.
The modal with the show grid targets :Admin:System:User (its grid supports picker mode).
Table of Contents
Properties
Methods
- userPicker() : PickerConfig
- resolveUserLabel() : string|null
-
suggestUsers()
: array<int, array{id: int, label: string, data: array
}> - userLabel() : string
Properties
$userManager
public
UserManager
$userManager
Attributes
- #[Inject]
Methods
userPicker()
protected
userPicker(string $formName, string $targetField[, string|null $emailField = null ]) : PickerConfig
Parameters
- $formName : string
-
name of the form holding the hidden field (
editForm) - $targetField : string
-
name of the hidden control (
ownerId,authorId, …) - $emailField : string|null = null
-
optional form field for the e-mail (multi-field mapping)
Return values
PickerConfigresolveUserLabel()
private
resolveUserLabel(int $id) : string|null
Parameters
- $id : int
Return values
string|nullsuggestUsers()
private
suggestUsers(string $query) : array<int, array{id: int, label: string, data: array}>
Parameters
- $query : string
Return values
array<int, array{id: int, label: string, data: arrayuserLabel()
private
userLabel(User $user) : string
Parameters
- $user : User