BranchTrait uses trait:short, trait:short
Own branches (pickup points) of a shipper tariff: one tariff has many branches.
Plain CRUD through ShipperTariffManager::saveBranch()
and ShipperTariffManager::deleteBranch().
The form opens in a sub-modal (ModalAwareTrait::getModalWindow()) layered over the open
tariff modal; one form serves add and edit, the hidden branchId field decides between
insert and update.
Deleting is AJAX, not a redirect: the branch section lives inside the open tariff modal and a full page redirect would close it.
The section is shown only when $editing is true (the tariff has an id the foreign key can
point to); ShipperTariffEdit::render()
fills $template->branches through loadBranchRows().
Table of Contents
Properties
- $editingBranchId : int|null
- Branch currently edited in the modal (`branchId`); null when adding a new one.
Methods
- handleAddBranch() : void
- handleDeleteBranch() : void
- Deletes a branch over AJAX (no redirect, which would close the open tariff modal).
- handleEditBranch() : void
- onBranchFormSuccess() : void
- createComponentBranchForm() : Form
- getModalWindow() : ModalWindow
- isTargetAllowed() : bool
- Returns whether the logged-in user may open the given admin target. For visibility (tiles, autocomplete, buttons); it does not throw.
- requirePrivilege() : void
- Throws 403 when the logged-in user lacks the given admin privilege.
- resolvePageTarget() : string|null
- Returns the RBAC key of the target page: `<presenter>:<action>`, e.g. `:Admin:System:User:show`.
- buildBranchModalContent() : string
- canManageBranches() : bool
- Branches can be managed only on an already saved tariff (the foreign key target must exist).
- findBranch() : ShipperTariffBranch|null
- flashBranchGuardError() : void
- formatBranchAddress() : string
- loadBranchRows() : array<int, array{id: int, name: string, address: string, active: bool}>
- Builds the branch cards, always filtered by `isManaged`: `false` is reserved for a future bulk sync of an external shipper network and is never listed in the admin.
- redrawBranchesAfterMutation() : void
- setBranchFormDefaults() : void
- showBranchModal() : void
Properties
$editingBranchId
Branch currently edited in the modal (`branchId`); null when adding a new one.
private
int|null
$editingBranchId
= null
Methods
handleAddBranch()
public
handleAddBranch() : void
handleDeleteBranch()
Deletes a branch over AJAX (no redirect, which would close the open tariff modal).
public
handleDeleteBranch(int $branchId) : void
The confirmation dialog comes from the template (data-grid-confirm); its JS handler is
delegated on document, so it works on any link.
Parameters
- $branchId : int
Attributes
- #[Requires]
- $methods: 'POST'
handleEditBranch()
public
handleEditBranch(int $branchId) : void
Parameters
- $branchId : int
onBranchFormSuccess()
public
onBranchFormSuccess(Form $form, ArrayHash<string|int, mixed> $values) : void
Parameters
- $form : Form
- $values : ArrayHash<string|int, mixed>
createComponentBranchForm()
protected
createComponentBranchForm() : Form
Return values
FormgetModalWindow()
protected
getModalWindow() : ModalWindow
Return values
ModalWindowisTargetAllowed()
Returns whether the logged-in user may open the given admin target. For visibility (tiles, autocomplete, buttons); it does not throw.
protected
isTargetAllowed(string|null $key) : bool
IMPORTANT: fail-closed like requirePrivilege(): an empty key and a presenter
without isAllowed() both mean no. A component that skips this question lists the
target to everyone.
Parameters
- $key : string|null
Return values
boolrequirePrivilege()
Throws 403 when the logged-in user lacks the given admin privilege.
protected
requirePrivilege(string $key) : void
Call it as the first statement of a mutating signal, before loading data, so the check cannot be bypassed by something being written first.
Parameters
- $key : string
resolvePageTarget()
Returns the RBAC key of the target page: `<presenter>:<action>`, e.g. `:Admin:System:User:show`.
protected
static resolvePageTarget(object|null $page) : string|null
Same interpretation as Menu::filterByPrivileges(), BasePresenter::authorizeListing() and PrivilegeCheckTrait::checkCurrentPrivilege(). The key is derived from the page target only, never from a file or class name.
Returns null when the page is missing or has no presenter, so there is nothing to allow.
Parameters
- $page : object|null
-
AdminPageentity (hydrated, hence justobject)
Return values
string|nullbuildBranchModalContent()
private
buildBranchModalContent() : string
Return values
stringcanManageBranches()
Branches can be managed only on an already saved tariff (the foreign key target must exist).
private
canManageBranches() : bool
Return values
boolfindBranch()
private
findBranch(int $branchId) : ShipperTariffBranch|null
Parameters
- $branchId : int
Return values
ShipperTariffBranch|nullflashBranchGuardError()
private
flashBranchGuardError(string $messageKey) : void
Parameters
- $messageKey : string
formatBranchAddress()
private
formatBranchAddress(ShipperTariffBranch $branch) : string
Parameters
- $branch : ShipperTariffBranch
Return values
stringloadBranchRows()
Builds the branch cards, always filtered by `isManaged`: `false` is reserved for a future bulk sync of an external shipper network and is never listed in the admin.
private
loadBranchRows() : array<int, array{id: int, name: string, address: string, active: bool}>
Return values
array<int, array{id: int, name: string, address: string, active: bool}>redrawBranchesAfterMutation()
private
redrawBranchesAfterMutation() : void
setBranchFormDefaults()
private
setBranchFormDefaults(Form $form) : void
Parameters
- $form : Form
showBranchModal()
private
showBranchModal() : void