PrivilegeGroupFormTrait uses trait:short
Form of a privilege group: header (key, module, entity, family), language tabs (name, description) and a Multiplier of privileges (key plus a checkbox for every role).
Multiplier pitfalls handled here:
- Existing rows are filled only through
$form->setDefaults(['privileges' => [...]]), never by a manualaddCopy()with data (setPrivilegeGroupFormDefaults()). addCopy()on a submitted form is a no-op, so it is not used at all.- A Multiplier row is a plain
Container;form-controlmust be set by hand in the template. - Role relations are written set-based (see UserRolePrivilegeMatrixManager::saveGroupPrivileges()), not by object-graph ToMany replace, which would delete all existing relations.
- A disabled owner cell on non-Api rows is a cosmetic
disabledattribute on the Html object in the template (rowBranch()), nevern:if: the control still exists and posts.
Table of Contents
Methods
- rowBranch() : string
- Returns the branch from the first key segment, with the same logic as Api `UserRolePrivilegeMatrixManager::branchFromKey()`: client and server must compute it identically, otherwise the UI and the stored state disagree. An invalid or empty key gives 'Admin' (the owner column stays disabled, a safe default).
- 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.
- addPrivilegeGroupTranslationFields() : void
- addPrivilegesMultiplier() : void
- Multiplier row: one `key` plus a checkbox for every role from the DB.
- flashPrivilegesError() : void
- Builds the message for a failed privilege write: a rejected conditional grant names the role and key, others are generic.
- ownerRoleId() : int|null
- Returns the id of the `owner` role (conditional=1), for the defense-in-depth guard on save.
- rolesList() : array<int, array{id: int, code: string, name: string, label: string, description: ?string, conditional: bool}>
- Returns roles from the DB for the Multiplier columns: `id`/`code`/`name`/`conditional`; `label` is the human name (system role translation, else DB name), `description` a short text (translated roles only).
- roleText() : string|null
- Translation of `admin.system.rbacRoles.<code>.<part>`, or `null` (unknown code shape / key not in the catalog).
- savePrivilegeGroupForm() : bool
- savePrivilegesRows() : string|null
- Builds the Multiplier rows plus the diff of deleted ids and saves them set-based through the Api.
- setPrivilegeGroupFormDefaults() : void
Methods
rowBranch()
Returns the branch from the first key segment, with the same logic as Api `UserRolePrivilegeMatrixManager::branchFromKey()`: client and server must compute it identically, otherwise the UI and the stored state disagree. An invalid or empty key gives 'Admin' (the owner column stays disabled, a safe default).
public
rowBranch(mixed $key) : string
Parameters
- $key : mixed
Return values
stringcreateComponentEditForm()
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
stringaddPrivilegeGroupTranslationFields()
private
addPrivilegeGroupTranslationFields(Form $form) : void
Parameters
- $form : Form
addPrivilegesMultiplier()
Multiplier row: one `key` plus a checkbox for every role from the DB.
private
addPrivilegesMultiplier(Form $form) : void
Parameters
- $form : Form
flashPrivilegesError()
Builds the message for a failed privilege write: a rejected conditional grant names the role and key, others are generic.
private
flashPrivilegesError(string $error) : void
Parameters
- $error : string
ownerRoleId()
Returns the id of the `owner` role (conditional=1), for the defense-in-depth guard on save.
private
ownerRoleId() : int|null
Return values
int|nullrolesList()
Returns roles from the DB for the Multiplier columns: `id`/`code`/`name`/`conditional`; `label` is the human name (system role translation, else DB name), `description` a short text (translated roles only).
private
rolesList() : array<int, array{id: int, code: string, name: string, label: string, description: ?string, conditional: bool}>
Return values
array<int, array{id: int, code: string, name: string, label: string, description: ?string, conditional: bool}>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|nullsavePrivilegeGroupForm()
private
savePrivilegeGroupForm(ArrayHash<string|int, mixed> $values) : bool
Parameters
- $values : ArrayHash<string|int, mixed>
Return values
boolsavePrivilegesRows()
Builds the Multiplier rows plus the diff of deleted ids and saves them set-based through the Api.
private
savePrivilegesRows(ArrayHash $values, int $groupId) : string|null
Parameters
- $values : ArrayHash
- $groupId : int
Return values
string|null —error code from the Api (null = saved)
setPrivilegeGroupFormDefaults()
private
setPrivilegeGroupFormDefaults(Form $form) : void
Parameters
- $form : Form