CoolCMS API

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

$userManager  : UserManager

Methods

userPicker()  : PickerConfig
resolveUserLabel()  : string|null
suggestUsers()  : array<int, array{id: int, label: string, data: array}>
userLabel()  : string

Properties

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
PickerConfig

resolveUserLabel()

private resolveUserLabel(int $id) : string|null
Parameters
$id : int
Return values
string|null

suggestUsers()

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: array}>
On this page

Search results