UserFormTrait uses trait:short
Add/edit form of a user.
The skeleton comes from BasePresenter::createForm(). Scalar
fields plus selects (payment region / language / user type / discount level). The roles
and groups relations (M2M) are handled separately below; externalLogins is not edited here.
The password is not stored as a column but passed to the Api through the save
$meta['password'] (UserManager::beforeSave
hashes it). It is required on add and optional on edit (empty = unchanged). Creating a
user in the admin suppresses the registration/activation e-mail by $meta['skipNotifications'].
regionId is derived from the selected payment region (server-side lookup). The country is
the ISO countryCode (select); the text country is filled by the Api save from the code
list. The selects draw from admin managers.
Table of Contents
Constants
- SET_ROLES_PRIVILEGE : string = ':Admin:System:User:setRoles'
- Privilege key "set roles" (currently only the admin role). Without it the role field is read-only and the save does not send `roleIds` at all, so the account roles stay as they are. The Api enforces it again (`:Api:System:User:setRoles`, `UserManager::beforeSave()` answers `USER_ROLE_ASSIGNMENT_DENIED`).
Methods
- createComponentEditForm() : Form
- roleDescription() : string|null
- Short description of a system role, or `null` when the role has no translation.
- roleLabel() : string
- Human-readable role name: translation of a system role, otherwise the DB name (`$dbName`), otherwise the code.
- addAccountFields() : void
- Credentials: username, e-mail, password (plus confirmation).
- addCompanyFields() : void
- Company data: company flag plus a conditionally required field.
- addPersonalFields() : void
- Personal and address data plus the payment region.
- addRelationFields() : void
- M2M relations: roles and groups (multiselect). Saved through the save `$meta` (DBAL sync in the Api).
- addSettingsFields() : void
- Account settings: language, type, discount, points, status, website.
- applyPaymentRegionDerived() : void
- Fills `regionId` from the selected payment region (the text `country` is derived by the Api from `countryCode`).
- buildUserEntity() : User
- canSetRoles() : bool
- Tells whether the logged-in editor may change user roles (see {@see self::SET_ROLES_PRIVILEGE}).
- prepareDiscountLevelOptions() : array<int, string>
- Discount level options: `id => "discount %"`.
- prepareGroupOptions() : array<int, string>
- Group options: `id => name` (`UserGroup` with `translations`).
- prepareLanguageOptions() : array<int, string>
- Language options: `id => name`.
- preparePaymentRegionOptions() : array<int, string>
- Payment region options: `id => name` (current language, fallback to the first non-empty one).
- prepareRoleOptions() : array<int, string>
- Role options: `id => name` (system roles translated via {@see RoleLabelTrait}, custom roles with the name from the DB).
- prepareUserTypeOptions() : array<int, string>
- User type options: `id => name`.
- roleText() : string|null
- Translation of `admin.system.rbacRoles.<code>.<part>`, or `null` (unknown code shape / key not in the catalog).
- saveUserForm() : bool
- Saves the form data. The redirect is handled by {@see \App\Core\Base\Admin\BasePresenter::createForm()}.
- selectedIds() : array<int, int>
- Positive integer ids from a multiselect value.
- setUserFormDefaults() : void
- submittedRoleIds() : array<int, int>
- Returns the resulting set of roles to save: submitted choices known to the offer (a role with `assignable = 0` is never offered, so the form never assigns it). Called only with the "set roles" privilege.
- tr() : string
- Translates a key in the form domain into a final string (for fields with `setTranslator(null)`).
- translatedName() : string
- Name of an entity with `translations` in the current language (fallback to the first non-empty one).
Constants
SET_ROLES_PRIVILEGE
Privilege key "set roles" (currently only the admin role). Without it the role field is read-only and the save does not send `roleIds` at all, so the account roles stay as they are. The Api enforces it again (`:Api:System:User:setRoles`, `UserManager::beforeSave()` answers `USER_ROLE_ASSIGNMENT_DENIED`).
private
string
SET_ROLES_PRIVILEGE
= ':Admin:System:User:setRoles'
Methods
createComponentEditForm()
protected
createComponentEditForm() : Form
Return values
FormroleDescription()
Short description of a system role, or `null` when the role has no translation.
protected
roleDescription(string $code) : string|null
Parameters
- $code : string
Return values
string|nullroleLabel()
Human-readable role name: translation of a system role, otherwise the DB name (`$dbName`), otherwise the code.
protected
roleLabel(string $code[, string|null $dbName = null ]) : string
Parameters
- $code : string
- $dbName : string|null = null
Return values
stringaddAccountFields()
Credentials: username, e-mail, password (plus confirmation).
private
addAccountFields(Form $form) : void
Parameters
- $form : Form
addCompanyFields()
Company data: company flag plus a conditionally required field.
private
addCompanyFields(Form $form) : void
Parameters
- $form : Form
addPersonalFields()
Personal and address data plus the payment region.
private
addPersonalFields(Form $form) : void
Parameters
- $form : Form
addRelationFields()
M2M relations: roles and groups (multiselect). Saved through the save `$meta` (DBAL sync in the Api).
private
addRelationFields(Form $form) : void
Parameters
- $form : Form
addSettingsFields()
Account settings: language, type, discount, points, status, website.
private
addSettingsFields(Form $form) : void
Parameters
- $form : Form
applyPaymentRegionDerived()
Fills `regionId` from the selected payment region (the text `country` is derived by the Api from `countryCode`).
private
applyPaymentRegionDerived(User $user, int|null $paymentRegionId) : void
Parameters
- $user : User
- $paymentRegionId : int|null
buildUserEntity()
private
buildUserEntity(ArrayHash<string|int, mixed> $values) : User
Parameters
- $values : ArrayHash<string|int, mixed>
Return values
UsercanSetRoles()
Tells whether the logged-in editor may change user roles (see {@see self::SET_ROLES_PRIVILEGE}).
private
canSetRoles() : bool
Return values
boolprepareDiscountLevelOptions()
Discount level options: `id => "discount %"`.
private
prepareDiscountLevelOptions() : array<int, string>
Return values
array<int, string>prepareGroupOptions()
Group options: `id => name` (`UserGroup` with `translations`).
private
prepareGroupOptions() : array<int, string>
Return values
array<int, string>prepareLanguageOptions()
Language options: `id => name`.
private
prepareLanguageOptions() : array<int, string>
Return values
array<int, string>preparePaymentRegionOptions()
Payment region options: `id => name` (current language, fallback to the first non-empty one).
private
preparePaymentRegionOptions() : array<int, string>
Return values
array<int, string>prepareRoleOptions()
Role options: `id => name` (system roles translated via {@see RoleLabelTrait}, custom roles with the name from the DB).
private
prepareRoleOptions() : array<int, string>
IMPORTANT: roles with conditional=1 (owner and future conditional roles) are not
offered: they are implicit grants derived at runtime, not roles assignable to a user
through cms_system_user_role_relations (the assignable=0 column targets exactly this).
Return values
array<int, string>prepareUserTypeOptions()
User type options: `id => name`.
private
prepareUserTypeOptions() : array<int, string>
Return values
array<int, string>roleText()
Translation of `admin.system.rbacRoles.<code>.<part>`, or `null` (unknown code shape / key not in the catalog).
private
roleText(string $code, string $part) : string|null
Parameters
- $code : string
- $part : string
Return values
string|nullsaveUserForm()
Saves the form data. The redirect is handled by {@see \App\Core\Base\Admin\BasePresenter::createForm()}.
private
saveUserForm(ArrayHash<string|int, mixed> $values, Form $form) : bool
Parameters
- $values : ArrayHash<string|int, mixed>
- $form : Form
Return values
boolselectedIds()
Positive integer ids from a multiselect value.
private
selectedIds(mixed $value) : array<int, int>
Parameters
- $value : mixed
Return values
array<int, int>setUserFormDefaults()
private
setUserFormDefaults(Form $form) : void
Parameters
- $form : Form
submittedRoleIds()
Returns the resulting set of roles to save: submitted choices known to the offer (a role with `assignable = 0` is never offered, so the form never assigns it). Called only with the "set roles" privilege.
private
submittedRoleIds(Form $form) : array<int, int>
Parameters
- $form : Form
Return values
array<int, int>tr()
Translates a key in the form domain into a final string (for fields with `setTranslator(null)`).
private
tr(string $key) : string
Parameters
- $key : string
Return values
stringtranslatedName()
Name of an entity with `translations` in the current language (fallback to the first non-empty one).
private
translatedName(object $entity) : string
Parameters
- $entity : object